initial add of sendVoice

This commit is contained in:
rqtqp 2025-02-25 10:16:02 +00:00
parent 35c00d0c84
commit 1b77adac21
4 changed files with 187 additions and 3 deletions

View file

@ -244,9 +244,15 @@ export class Telegram implements INodeType {
{
name: 'Send Audio',
value: 'sendAudio',
description: 'Send a audio file',
description: 'Send an audio file',
action: 'Send an audio file',
},
{
name: 'Send Voice',
value: 'sendVoice',
description: 'Send a voice message',
action: 'Send a voice message',
},
{
name: 'Send Chat Action',
value: 'sendChatAction',
@ -333,6 +339,7 @@ export class Telegram implements INodeType {
'setTitle',
'sendAnimation',
'sendAudio',
'sendVoice',
'sendChatAction',
'sendDocument',
'sendLocation',
@ -706,7 +713,7 @@ export class Telegram implements INodeType {
'Unique identifier for the target chat or username, To find your chat ID ask @get_id_bot',
},
// ----------------------------------
// message:sendAnimation/sendAudio/sendDocument/sendPhoto/sendSticker/sendVideo
// message:sendAnimation/sendAudio/sendVoice/sendDocument/sendPhoto/sendSticker/sendVideo
// ----------------------------------
{
@ -720,6 +727,7 @@ export class Telegram implements INodeType {
operation: [
'sendAnimation',
'sendAudio',
'sendVoice',
'sendDocument',
'sendPhoto',
'sendVideo',
@ -742,6 +750,7 @@ export class Telegram implements INodeType {
operation: [
'sendAnimation',
'sendAudio',
'sendVoice',
'sendDocument',
'sendPhoto',
'sendVideo',
@ -845,6 +854,24 @@ export class Telegram implements INodeType {
description:
'Audio file to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), an HTTP URL for Telegram to get a file from the Internet.',
},
// ----------------------------------
// message:sendVoice
// ----------------------------------
{
displayName: 'Voice',
name: 'file',
type: 'string',
default: '',
displayOptions: {
show: {
operation: ['sendVoice'],
resource: ['message'],
binaryData: [false],
},
},
description:
'Voice message to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), an HTTP URL for Telegram to get a file from the Internet.',
},
// ----------------------------------
// message:sendChatAction
@ -870,6 +897,11 @@ export class Telegram implements INodeType {
value: 'record_audio',
action: 'Record audio',
},
{
name: 'Record Voice',
value: 'record_voice',
action: 'Record voice',
},
{
name: 'Record Video',
value: 'record_video',
@ -1159,6 +1191,7 @@ export class Telegram implements INodeType {
'sendSticker',
'sendVideo',
'sendAudio',
'sendVoice',
'sendLocation',
],
resource: ['message'],
@ -1515,6 +1548,7 @@ export class Telegram implements INodeType {
'editMessageText',
'sendAnimation',
'sendAudio',
'sendVoice',
'sendDocument',
'sendLocation',
'sendMessage',
@ -1547,6 +1581,7 @@ export class Telegram implements INodeType {
'/operation': [
'sendAnimation',
'sendAudio',
'sendVoice',
'sendDocument',
'sendPhoto',
'sendVideo',
@ -1590,7 +1625,7 @@ export class Telegram implements INodeType {
},
displayOptions: {
show: {
'/operation': ['sendAnimation', 'sendAudio', 'sendVideo'],
'/operation': ['sendAnimation', 'sendAudio', 'sendVoice', 'sendVideo'],
},
},
default: 0,
@ -1606,6 +1641,7 @@ export class Telegram implements INodeType {
'/operation': [
'sendAnimation',
'sendAudio',
'sendVoice',
'sendDocument',
'sendPhoto',
'sendVideo',
@ -1656,6 +1692,7 @@ export class Telegram implements INodeType {
'editMessageText',
'sendAnimation',
'sendAudio',
'sendVoice',
'sendMessage',
'sendPhoto',
'sendVideo',
@ -1699,6 +1736,7 @@ export class Telegram implements INodeType {
'/operation': [
'sendAnimation',
'sendAudio',
'sendVoice',
'sendChatAction',
'sendDocument',
'sendLocation',
@ -1989,6 +2027,18 @@ export class Telegram implements INodeType {
// Add additional fields and replyMarkup
addAdditionalFields.call(this, body, i);
} else if (operation === 'sendVoice') {
// ----------------------------------
// message:sendVoice
// ----------------------------------
endpoint = 'sendVoice';
body.chat_id = this.getNodeParameter('chatId', i) as string;
body.audio = this.getNodeParameter('file', i, '') as string;
// Add additional fields and replyMarkup
addAdditionalFields.call(this, body, i);
} else if (operation === 'sendChatAction') {
// ----------------------------------
// message:sendChatAction

View file

@ -0,0 +1,104 @@
{
"type": "object",
"properties": {
"ok": {
"type": "boolean"
},
"result": {
"type": "object",
"properties": {
"message_id": {
"type": "integer"
},
"from": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"is_bot": {
"type": "boolean"
},
"first_name": {
"type": "string"
},
"username": {
"type": "string"
}
},
"required": [
"id",
"is_bot",
"first_name",
"username"
]
},
"chat": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"first_name": {
"type": "string"
},
"type": {
"type": "string"
},
"last_name": {
"type": "string"
}
},
"required": [
"id",
"type"
]
},
"date": {
"type": "integer"
},
"voice": {
"type": "object",
"properties": {
"duration": {
"type": "integer"
},
"file_name": {
"type": "string"
},
"mime_type": {
"type": "string"
},
"file_id": {
"type": "string"
},
"file_unique_id": {
"type": "string"
},
"file_size": {
"type": "integer"
}
},
"required": [
"duration",
"file_name",
"mime_type",
"file_id",
"file_unique_id",
"file_size"
]
}
},
"required": [
"message_id",
"from",
"chat",
"date"
]
}
},
"required": [
"ok",
"result"
]
}

View file

@ -381,6 +381,34 @@ export const sendAudioResponse = {
},
},
};
export const sendVoiceResponse = {
ok: true,
result: {
message_id: 47,
from: {
id: 9876543210,
is_bot: true,
first_name: '@n8n',
username: 'n8n_test_bot',
},
chat: {
id: 123456789,
first_name: 'Nathan',
last_name: 'W',
username: 'n8n',
type: 'private',
},
date: 1732969291,
audio: {
duration: 3,
file_name: 'sample-3s.mp3',
mime_type: 'audio/mpeg',
file_id: 'CQACAgQAAxkDAAMuZ0sDSxCh3hW89NQa-eTpxKioqGAAAjsEAAIBCU1SGtsPA4N9TSo2BA',
file_unique_id: 'AgADOwQAAgEJTVI',
file_size: 52079,
},
},
};
export const getMemberResponse = {
ok: true,

View file

@ -11,6 +11,7 @@ import {
chatAdministratorsResponse,
sendAnimationMessageResponse,
sendAudioResponse,
sendVoiceResponse,
getMemberResponse,
} from './apiResponses';
import { FAKE_CREDENTIALS_DATA } from '../../../../test/nodes/FakeCredentialsMap';
@ -38,6 +39,7 @@ describe('Telegram', () => {
mock.post('/bottestToken/getChatAdministrators').reply(200, chatAdministratorsResponse);
mock.post('/bottestToken/sendAnimation').reply(200, sendAnimationMessageResponse);
mock.post('/bottestToken/sendAudio').reply(200, sendAudioResponse);
mock.post('/bottestToken/sendVoice').reply(200, sendVoiceResponse);
mock.post('/bottestToken/getChatMember').reply(200, getMemberResponse);
});