mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-28 21:07:39 +00:00
src: Minor fixes
This commit is contained in:
parent
d6083e4327
commit
b774ff436f
@ -24,6 +24,13 @@ Changed:
|
||||
1. Update *TelegramBot#answerCallbackQuery()* signature (by @GochoMugo)
|
||||
1. Improve default error logging of `polling_error` and `webhook_error`
|
||||
|
||||
Deprecated:
|
||||
|
||||
1. Sending files: *(See [usage guide][usage-sending-file])* (by @hufan-akari, @GochoMugo)
|
||||
* Error will **not** be thrown if `Buffer` is used and file-type could **not** be detected.
|
||||
* Filename will **not** be set to `data.${ext}` if `Buffer` is used
|
||||
* Content type will **not** default to `null` or `undefined`
|
||||
|
||||
Fixed:
|
||||
|
||||
1. Fix game example (by @MCSH)
|
||||
@ -184,6 +191,8 @@ Fixed:
|
||||
1. Fix typos (by oflisback)
|
||||
|
||||
|
||||
[usage-sending-files]:https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md#sending-files-options
|
||||
|
||||
[0.25.0]:https://github.com/yagop/node-telegram-bot-api/releases/tag/v0.25.0
|
||||
[0.26.0]:https://github.com/yagop/node-telegram-bot-api/releases/tag/v0.26.0
|
||||
[0.27.0]:https://github.com/yagop/node-telegram-bot-api/releases/tag/v0.27.0
|
||||
|
36
doc/api.md
36
doc/api.md
@ -30,13 +30,13 @@ TelegramBot
|
||||
* [.sendMessage(chatId, text, [options])](#TelegramBot+sendMessage) ⇒ <code>Promise</code>
|
||||
* [.answerInlineQuery(inlineQueryId, results, [options])](#TelegramBot+answerInlineQuery) ⇒ <code>Promise</code>
|
||||
* [.forwardMessage(chatId, fromChatId, messageId, [options])](#TelegramBot+forwardMessage) ⇒ <code>Promise</code>
|
||||
* [.sendPhoto(chatId, photo, [options], [fileOpts])](#TelegramBot+sendPhoto) ⇒ <code>Promise</code>
|
||||
* [.sendAudio(chatId, audio, [options], [fileOpts])](#TelegramBot+sendAudio) ⇒ <code>Promise</code>
|
||||
* [.sendDocument(chatId, doc, [options], [fileOpts])](#TelegramBot+sendDocument) ⇒ <code>Promise</code>
|
||||
* [.sendPhoto(chatId, photo, [options], [fileOptions])](#TelegramBot+sendPhoto) ⇒ <code>Promise</code>
|
||||
* [.sendAudio(chatId, audio, [options], [fileOptions])](#TelegramBot+sendAudio) ⇒ <code>Promise</code>
|
||||
* [.sendDocument(chatId, doc, [options], [fileOptions])](#TelegramBot+sendDocument) ⇒ <code>Promise</code>
|
||||
* [.sendSticker(chatId, sticker, [options])](#TelegramBot+sendSticker) ⇒ <code>Promise</code>
|
||||
* [.sendVideo(chatId, video, [options], [fileOpts])](#TelegramBot+sendVideo) ⇒ <code>Promise</code>
|
||||
* [.sendVideoNote(chatId, videoNote, [options], [fileOpts])](#TelegramBot+sendVideoNote) ⇒ <code>Promise</code>
|
||||
* [.sendVoice(chatId, voice, [options], [fileOpts])](#TelegramBot+sendVoice) ⇒ <code>Promise</code>
|
||||
* [.sendVideo(chatId, video, [options], [fileOptions])](#TelegramBot+sendVideo) ⇒ <code>Promise</code>
|
||||
* [.sendVideoNote(chatId, videoNote, [options], [fileOptions])](#TelegramBot+sendVideoNote) ⇒ <code>Promise</code>
|
||||
* [.sendVoice(chatId, voice, [options], [fileOptions])](#TelegramBot+sendVoice) ⇒ <code>Promise</code>
|
||||
* [.sendChatAction(chatId, action, [options])](#TelegramBot+sendChatAction) ⇒ <code>Promise</code>
|
||||
* [.kickChatMember(chatId, userId, [options])](#TelegramBot+kickChatMember) ⇒ <code>Promise</code>
|
||||
* [.unbanChatMember(chatId, userId, [options])](#TelegramBot+unbanChatMember) ⇒ <code>Promise</code>
|
||||
@ -339,7 +339,7 @@ Forward messages of any kind.
|
||||
|
||||
<a name="TelegramBot+sendPhoto"></a>
|
||||
|
||||
### telegramBot.sendPhoto(chatId, photo, [options], [fileOpts]) ⇒ <code>Promise</code>
|
||||
### telegramBot.sendPhoto(chatId, photo, [options], [fileOptions]) ⇒ <code>Promise</code>
|
||||
Send photo
|
||||
|
||||
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||
@ -354,11 +354,11 @@ Send photo
|
||||
| chatId | <code>Number</code> | <code>String</code> | Unique identifier for the message recipient |
|
||||
| photo | <code>String</code> | <code>stream.Stream</code> | <code>Buffer</code> | A file path or a Stream. Can also be a `file_id` previously uploaded |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
| [fileOpts] | <code>Object</code> | Optional file related meta-data |
|
||||
| [fileOptions] | <code>Object</code> | Optional file related meta-data |
|
||||
|
||||
<a name="TelegramBot+sendAudio"></a>
|
||||
|
||||
### telegramBot.sendAudio(chatId, audio, [options], [fileOpts]) ⇒ <code>Promise</code>
|
||||
### telegramBot.sendAudio(chatId, audio, [options], [fileOptions]) ⇒ <code>Promise</code>
|
||||
Send audio
|
||||
|
||||
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||
@ -373,11 +373,11 @@ Send audio
|
||||
| chatId | <code>Number</code> | <code>String</code> | Unique identifier for the message recipient |
|
||||
| audio | <code>String</code> | <code>stream.Stream</code> | <code>Buffer</code> | A file path, Stream or Buffer. Can also be a `file_id` previously uploaded. |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
| [fileOpts] | <code>Object</code> | Optional file related meta-data |
|
||||
| [fileOptions] | <code>Object</code> | Optional file related meta-data |
|
||||
|
||||
<a name="TelegramBot+sendDocument"></a>
|
||||
|
||||
### telegramBot.sendDocument(chatId, doc, [options], [fileOpts]) ⇒ <code>Promise</code>
|
||||
### telegramBot.sendDocument(chatId, doc, [options], [fileOptions]) ⇒ <code>Promise</code>
|
||||
Send Document
|
||||
|
||||
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||
@ -392,7 +392,7 @@ Send Document
|
||||
| chatId | <code>Number</code> | <code>String</code> | Unique identifier for the message recipient |
|
||||
| doc | <code>String</code> | <code>stream.Stream</code> | <code>Buffer</code> | A file path, Stream or Buffer. Can also be a `file_id` previously uploaded. |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
| [fileOpts] | <code>Object</code> | Optional file related meta-data |
|
||||
| [fileOptions] | <code>Object</code> | Optional file related meta-data |
|
||||
|
||||
<a name="TelegramBot+sendSticker"></a>
|
||||
|
||||
@ -410,7 +410,7 @@ Send .webp stickers.
|
||||
|
||||
<a name="TelegramBot+sendVideo"></a>
|
||||
|
||||
### telegramBot.sendVideo(chatId, video, [options], [fileOpts]) ⇒ <code>Promise</code>
|
||||
### telegramBot.sendVideo(chatId, video, [options], [fileOptions]) ⇒ <code>Promise</code>
|
||||
Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
|
||||
|
||||
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||
@ -425,11 +425,11 @@ Use this method to send video files, Telegram clients support mp4 videos (other
|
||||
| chatId | <code>Number</code> | <code>String</code> | Unique identifier for the message recipient |
|
||||
| video | <code>String</code> | <code>stream.Stream</code> | <code>Buffer</code> | A file path or Stream. Can also be a `file_id` previously uploaded. |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
| [fileOpts] | <code>Object</code> | Optional file related meta-data |
|
||||
| [fileOptions] | <code>Object</code> | Optional file related meta-data |
|
||||
|
||||
<a name="TelegramBot+sendVideoNote"></a>
|
||||
|
||||
### telegramBot.sendVideoNote(chatId, videoNote, [options], [fileOpts]) ⇒ <code>Promise</code>
|
||||
### telegramBot.sendVideoNote(chatId, videoNote, [options], [fileOptions]) ⇒ <code>Promise</code>
|
||||
Use this method to send rounded square videos of upto 1 minute long.
|
||||
|
||||
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||
@ -445,11 +445,11 @@ Use this method to send rounded square videos of upto 1 minute long.
|
||||
| chatId | <code>Number</code> | <code>String</code> | Unique identifier for the message recipient |
|
||||
| videoNote | <code>String</code> | <code>stream.Stream</code> | <code>Buffer</code> | A file path or Stream. Can also be a `file_id` previously uploaded. |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
| [fileOpts] | <code>Object</code> | Optional file related meta-data |
|
||||
| [fileOptions] | <code>Object</code> | Optional file related meta-data |
|
||||
|
||||
<a name="TelegramBot+sendVoice"></a>
|
||||
|
||||
### telegramBot.sendVoice(chatId, voice, [options], [fileOpts]) ⇒ <code>Promise</code>
|
||||
### telegramBot.sendVoice(chatId, voice, [options], [fileOptions]) ⇒ <code>Promise</code>
|
||||
Send voice
|
||||
|
||||
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||
@ -464,7 +464,7 @@ Send voice
|
||||
| chatId | <code>Number</code> | <code>String</code> | Unique identifier for the message recipient |
|
||||
| voice | <code>String</code> | <code>stream.Stream</code> | <code>Buffer</code> | A file path, Stream or Buffer. Can also be a `file_id` previously uploaded. |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
| [fileOpts] | <code>Object</code> | Optional file related meta-data |
|
||||
| [fileOptions] | <code>Object</code> | Optional file related meta-data |
|
||||
|
||||
<a name="TelegramBot+sendChatAction"></a>
|
||||
|
||||
|
@ -129,7 +129,7 @@ const fileOpts = {
|
||||
bot.sendAudio(chatId, data, {}, fileOpts);
|
||||
```
|
||||
|
||||
<a name="sending-files-metadata"></a>
|
||||
<a name="sending-files-options"></a>
|
||||
### File Options (metadata)
|
||||
|
||||
When sending files, the library automatically resolves
|
||||
|
@ -284,9 +284,9 @@ class TelegramBot extends EventEmitter {
|
||||
* Format data to be uploaded; handles file paths, streams and buffers
|
||||
* @param {String} type
|
||||
* @param {String|stream.Stream|Buffer} data
|
||||
* @param {Object} fileOpts File options
|
||||
* @param {String} [fileOpts.filename] File name
|
||||
* @param {String} [fileOpts.contentType] Content type (i.e. MIME)
|
||||
* @param {Object} fileOptions File options
|
||||
* @param {String} [fileOptions.filename] File name
|
||||
* @param {String} [fileOptions.contentType] Content type (i.e. MIME)
|
||||
* @return {Array} formatted
|
||||
* @return {Object} formatted[0] formData
|
||||
* @return {String} formatted[1] fileId
|
||||
@ -294,17 +294,19 @@ class TelegramBot extends EventEmitter {
|
||||
* @see https://npmjs.com/package/file-type
|
||||
* @private
|
||||
*/
|
||||
_formatSendData(type, data, fileOpts = {}) {
|
||||
_formatSendData(type, data, fileOptions = {}) {
|
||||
let filedata = data;
|
||||
let filename = fileOpts.filename;
|
||||
let contentType = fileOpts.contentType;
|
||||
let filename = fileOptions.filename;
|
||||
let contentType = fileOptions.contentType;
|
||||
|
||||
if (data instanceof stream.Stream) {
|
||||
if (!filename && data.path) {
|
||||
// Will be 'null' if could not be parsed.
|
||||
// For example, 'data.path' === '/?id=123' from 'request("https://example.com/?id=123")'
|
||||
const url = URL.parse(path.basename(data.path.toString()));
|
||||
filename = qs.unescape(url.pathname);
|
||||
if (url.pathname) {
|
||||
filename = qs.unescape(url.pathname);
|
||||
}
|
||||
}
|
||||
} else if (Buffer.isBuffer(data)) {
|
||||
if (!filename && !process.env.NTBA_FIX_350) {
|
||||
@ -701,18 +703,18 @@ class TelegramBot extends EventEmitter {
|
||||
* @param {String|stream.Stream|Buffer} photo A file path or a Stream. Can
|
||||
* also be a `file_id` previously uploaded
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @param {Object} [fileOpts] Optional file related meta-data
|
||||
* @param {Object} [fileOptions] Optional file related meta-data
|
||||
* @return {Promise}
|
||||
* @see https://core.telegram.org/bots/api#sendphoto
|
||||
* @see https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md#sending-files
|
||||
*/
|
||||
sendPhoto(chatId, photo, options = {}, fileOpts = {}) {
|
||||
sendPhoto(chatId, photo, options = {}, fileOptions = {}) {
|
||||
const opts = {
|
||||
qs: options,
|
||||
};
|
||||
opts.qs.chat_id = chatId;
|
||||
try {
|
||||
const sendData = this._formatSendData('photo', photo, fileOpts);
|
||||
const sendData = this._formatSendData('photo', photo, fileOptions);
|
||||
opts.formData = sendData[0];
|
||||
opts.qs.photo = sendData[1];
|
||||
} catch (ex) {
|
||||
@ -727,18 +729,18 @@ class TelegramBot extends EventEmitter {
|
||||
* @param {String|stream.Stream|Buffer} audio A file path, Stream or Buffer.
|
||||
* Can also be a `file_id` previously uploaded.
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @param {Object} [fileOpts] Optional file related meta-data
|
||||
* @param {Object} [fileOptions] Optional file related meta-data
|
||||
* @return {Promise}
|
||||
* @see https://core.telegram.org/bots/api#sendaudio
|
||||
* @see https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md#sending-files
|
||||
*/
|
||||
sendAudio(chatId, audio, options = {}, fileOpts = {}) {
|
||||
sendAudio(chatId, audio, options = {}, fileOptions = {}) {
|
||||
const opts = {
|
||||
qs: options
|
||||
};
|
||||
opts.qs.chat_id = chatId;
|
||||
try {
|
||||
const sendData = this._formatSendData('audio', audio, fileOpts);
|
||||
const sendData = this._formatSendData('audio', audio, fileOptions);
|
||||
opts.formData = sendData[0];
|
||||
opts.qs.audio = sendData[1];
|
||||
} catch (ex) {
|
||||
@ -753,18 +755,18 @@ class TelegramBot extends EventEmitter {
|
||||
* @param {String|stream.Stream|Buffer} doc A file path, Stream or Buffer.
|
||||
* Can also be a `file_id` previously uploaded.
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @param {Object} [fileOpts] Optional file related meta-data
|
||||
* @param {Object} [fileOptions] Optional file related meta-data
|
||||
* @return {Promise}
|
||||
* @see https://core.telegram.org/bots/api#sendDocument
|
||||
* @see https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md#sending-files
|
||||
*/
|
||||
sendDocument(chatId, doc, options = {}, fileOpts = {}) {
|
||||
sendDocument(chatId, doc, options = {}, fileOptions = {}) {
|
||||
const opts = {
|
||||
qs: options
|
||||
};
|
||||
opts.qs.chat_id = chatId;
|
||||
try {
|
||||
const sendData = this._formatSendData('document', doc, fileOpts);
|
||||
const sendData = this._formatSendData('document', doc, fileOptions);
|
||||
opts.formData = sendData[0];
|
||||
opts.qs.document = sendData[1];
|
||||
} catch (ex) {
|
||||
@ -803,18 +805,18 @@ class TelegramBot extends EventEmitter {
|
||||
* @param {String|stream.Stream|Buffer} video A file path or Stream.
|
||||
* Can also be a `file_id` previously uploaded.
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @param {Object} [fileOpts] Optional file related meta-data
|
||||
* @param {Object} [fileOptions] Optional file related meta-data
|
||||
* @return {Promise}
|
||||
* @see https://core.telegram.org/bots/api#sendvideo
|
||||
* @see https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md#sending-files
|
||||
*/
|
||||
sendVideo(chatId, video, options = {}, fileOpts = {}) {
|
||||
sendVideo(chatId, video, options = {}, fileOptions = {}) {
|
||||
const opts = {
|
||||
qs: options
|
||||
};
|
||||
opts.qs.chat_id = chatId;
|
||||
try {
|
||||
const sendData = this._formatSendData('video', video, fileOpts);
|
||||
const sendData = this._formatSendData('video', video, fileOptions);
|
||||
opts.formData = sendData[0];
|
||||
opts.qs.video = sendData[1];
|
||||
} catch (ex) {
|
||||
@ -829,19 +831,19 @@ class TelegramBot extends EventEmitter {
|
||||
* @param {String|stream.Stream|Buffer} videoNote A file path or Stream.
|
||||
* Can also be a `file_id` previously uploaded.
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @param {Object} [fileOpts] Optional file related meta-data
|
||||
* @param {Object} [fileOptions] Optional file related meta-data
|
||||
* @return {Promise}
|
||||
* @info The length parameter is actually optional. However, the API (at time of writing) requires you to always provide it until it is fixed.
|
||||
* @see https://core.telegram.org/bots/api#sendvideonote
|
||||
* @see https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md#sending-files
|
||||
*/
|
||||
sendVideoNote(chatId, videoNote, options = {}, fileOpts = {}) {
|
||||
sendVideoNote(chatId, videoNote, options = {}, fileOptions = {}) {
|
||||
const opts = {
|
||||
qs: options
|
||||
};
|
||||
opts.qs.chat_id = chatId;
|
||||
try {
|
||||
const sendData = this._formatSendData('video_note', videoNote, fileOpts);
|
||||
const sendData = this._formatSendData('video_note', videoNote, fileOptions);
|
||||
opts.formData = sendData[0];
|
||||
opts.qs.video_note = sendData[1];
|
||||
} catch (ex) {
|
||||
@ -856,18 +858,18 @@ class TelegramBot extends EventEmitter {
|
||||
* @param {String|stream.Stream|Buffer} voice A file path, Stream or Buffer.
|
||||
* Can also be a `file_id` previously uploaded.
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @param {Object} [fileOpts] Optional file related meta-data
|
||||
* @param {Object} [fileOptions] Optional file related meta-data
|
||||
* @return {Promise}
|
||||
* @see https://core.telegram.org/bots/api#sendvoice
|
||||
* @see https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md#sending-files
|
||||
*/
|
||||
sendVoice(chatId, voice, options = {}, fileOpts = {}) {
|
||||
sendVoice(chatId, voice, options = {}, fileOptions = {}) {
|
||||
const opts = {
|
||||
qs: options
|
||||
};
|
||||
opts.qs.chat_id = chatId;
|
||||
try {
|
||||
const sendData = this._formatSendData('voice', voice, fileOpts);
|
||||
const sendData = this._formatSendData('voice', voice, fileOptions);
|
||||
opts.formData = sendData[0];
|
||||
opts.qs.voice = sendData[1];
|
||||
} catch (ex) {
|
||||
|
@ -4,13 +4,13 @@ const path = require('path');
|
||||
const TelegramBot = require('..');
|
||||
|
||||
const paths = {
|
||||
audio: path.join(__dirname, "data/audio.mp3"),
|
||||
audio: path.join(__dirname, 'data/audio.mp3'),
|
||||
};
|
||||
|
||||
|
||||
// TODO:Enable all other tests
|
||||
describe.only('sending files', function sendfileSuite() {
|
||||
const bot = new TelegramBot("token");
|
||||
const bot = new TelegramBot('token ');
|
||||
|
||||
before(function beforeSuite() {
|
||||
process.env.NTBA_FIX_350 = 1;
|
||||
@ -26,7 +26,6 @@ describe.only('sending files', function sendfileSuite() {
|
||||
const buffer = fs.readFileSync(paths.audio);
|
||||
const nonDetectableBuffer = fs.readFileSync(__filename);
|
||||
const filepath = paths.audio;
|
||||
const fileId = 'fileId';
|
||||
const files = [stream, nonPathStream, buffer, nonDetectableBuffer, filepath];
|
||||
|
||||
delete nonPathStream.path;
|
||||
@ -42,7 +41,8 @@ describe.only('sending files', function sendfileSuite() {
|
||||
|
||||
it('(2) Stream#path', function test() {
|
||||
if (!stream.path) {
|
||||
return this.skip('Stream#path unsupported');
|
||||
this.skip('Stream#path unsupported');
|
||||
return;
|
||||
}
|
||||
const [{ [type]: data }] = bot._formatSendData(type, stream);
|
||||
assert.equal(data.options.filename, path.basename(paths.audio));
|
||||
@ -72,7 +72,8 @@ describe.only('sending files', function sendfileSuite() {
|
||||
|
||||
it('(2) Stream#path', function test() {
|
||||
if (!stream.path) {
|
||||
return this.skip('Stream#path unsupported');
|
||||
this.skip('Stream#path unsupported');
|
||||
return;
|
||||
}
|
||||
const [{ [type]: data }] = bot._formatSendData(type, stream);
|
||||
assert.equal(data.options.contentType, 'audio/mpeg');
|
||||
@ -104,6 +105,5 @@ describe.only('sending files', function sendfileSuite() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user