mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-28 21:07:39 +00:00
added sendVoice function
This commit is contained in:
parent
f66ce031cb
commit
b34caa84c5
18
README.md
18
README.md
@ -23,7 +23,7 @@ bot.on('text', function (msg) {
|
|||||||
There are some other examples on [examples](https://github.com/yagop/node-telegram-bot-api/tree/master/examples).
|
There are some other examples on [examples](https://github.com/yagop/node-telegram-bot-api/tree/master/examples).
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
Every time TelegramBot receives a message, it emits a `message`. Depending on which [message](https://core.telegram.org/bots/api#message) was received, emits an event from this ones: `text`, `audio`, `document`, `photo`, `sticker`, `video`, `contact`, `location`, `new_chat_participant`, `left_chat_participant`, `new_chat_title`, `new_chat_photo`, `delete_chat_photo`, `group_chat_created`. Its much better to listen a specific event rather than a `message` in order to stay safe from the content.
|
Every time TelegramBot receives a message, it emits a `message`. Depending on which [message](https://core.telegram.org/bots/api#message) was received, emits an event from this ones: `text`, `audio`, `document`, `photo`, `sticker`, `video`, `voice`, `contact`, `location`, `new_chat_participant`, `left_chat_participant`, `new_chat_title`, `new_chat_photo`, `delete_chat_photo`, `group_chat_created`. Its much better to listen a specific event rather than a `message` in order to stay safe from the content.
|
||||||
* * *
|
* * *
|
||||||
|
|
||||||
|
|
||||||
@ -194,6 +194,22 @@ See: https://core.telegram.org/bots/api#sendvideo
|
|||||||
|
|
||||||
* **Promise**
|
* **Promise**
|
||||||
|
|
||||||
|
## sendVoice(chatId, A, [options])
|
||||||
|
|
||||||
|
Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document).
|
||||||
|
|
||||||
|
See: https://core.telegram.org/bots/api#sendvoice
|
||||||
|
|
||||||
|
### Params:
|
||||||
|
|
||||||
|
* **Number|String** *chatId* Unique identifier for the message recipient
|
||||||
|
* **String|stream.Stream** *A* file path or a Stream. Can also be a `file_id` previously uploaded.
|
||||||
|
* **Object** *[options]* Additional Telegram query options
|
||||||
|
|
||||||
|
### Return:
|
||||||
|
|
||||||
|
* **Promise**
|
||||||
|
|
||||||
## sendChatAction(chatId, action)
|
## sendChatAction(chatId, action)
|
||||||
|
|
||||||
Send chat action.
|
Send chat action.
|
||||||
|
@ -34,7 +34,7 @@ var TelegramBot = function (token, options) {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
this.token = token;
|
this.token = token;
|
||||||
this.messageTypes = [
|
this.messageTypes = [
|
||||||
'text', 'audio', 'document', 'photo', 'sticker', 'video', 'contact',
|
'text', 'audio', 'document', 'photo', 'sticker', 'video', 'voice', 'contact',
|
||||||
'location', 'new_chat_participant', 'left_chat_participant', 'new_chat_title',
|
'location', 'new_chat_participant', 'left_chat_participant', 'new_chat_title',
|
||||||
'new_chat_photo', 'delete_chat_photo', 'group_chat_created'
|
'new_chat_photo', 'delete_chat_photo', 'group_chat_created'
|
||||||
]; // Telegram message events
|
]; // Telegram message events
|
||||||
@ -301,6 +301,26 @@ TelegramBot.prototype.sendVideo = function (chatId, video, options) {
|
|||||||
return this._request('sendVideo', opts);
|
return this._request('sendVideo', opts);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send voice
|
||||||
|
* @param {Number|String} chatId Unique identifier for the message recipient
|
||||||
|
* @param {String|stream.Stream} voice A file path or a Stream. Can
|
||||||
|
* also be a `file_id` previously uploaded.
|
||||||
|
* @param {Object} [options] Additional Telegram query options
|
||||||
|
* @return {Promise}
|
||||||
|
* @see https://core.telegram.org/bots/api#sendvoice
|
||||||
|
*/
|
||||||
|
TelegramBot.prototype.sendVoice = function (chatId, voice, options) {
|
||||||
|
var opts = {
|
||||||
|
qs: options || {}
|
||||||
|
};
|
||||||
|
opts.qs.chat_id = chatId;
|
||||||
|
var content = this._formatSendData('voice', voice);
|
||||||
|
opts.formData = content[0];
|
||||||
|
opts.qs.voice = content[1];
|
||||||
|
return this._request('sendVoice', opts);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send chat action.
|
* Send chat action.
|
||||||
|
@ -330,6 +330,17 @@ describe('Telegram', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#sendVoice', function () {
|
||||||
|
it('should send an OGG audio as voice', function (done) {
|
||||||
|
var bot = new Telegram(TOKEN);
|
||||||
|
var voice = request('https://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg');
|
||||||
|
bot.sendVoice(USERID, voice).then(function (resp) {
|
||||||
|
resp.should.be.an.instanceOf(Object);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('#getUserProfilePhotos', function () {
|
describe('#getUserProfilePhotos', function () {
|
||||||
it('should get user profile photos', function (done) {
|
it('should get user profile photos', function (done) {
|
||||||
var bot = new Telegram(TOKEN);
|
var bot = new Telegram(TOKEN);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user