mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-22 18:07:16 +00:00
chore/mr: Merge MR #720
This commit is contained in:
commit
0b8ca03b54
@ -5,6 +5,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [Unreleased][Unreleased]
|
||||
|
||||
Added:
|
||||
|
||||
1. Support Bot API v4.2: (by @kamikazechaser)
|
||||
* Add methods: *TelegramBot#sendPoll()*, *TelegramBot#stopPoll()*
|
||||
* Support events: *poll*
|
||||
|
||||
|
||||
* * *
|
||||
|
35
doc/api.md
35
doc/api.md
@ -61,6 +61,8 @@ TelegramBot
|
||||
* [.stopMessageLiveLocation([options])](#TelegramBot+stopMessageLiveLocation) ⇒ <code>Promise</code>
|
||||
* [.sendVenue(chatId, latitude, longitude, title, address, [options])](#TelegramBot+sendVenue) ⇒ <code>Promise</code>
|
||||
* [.sendContact(chatId, phoneNumber, firstName, [options])](#TelegramBot+sendContact) ⇒ <code>Promise</code>
|
||||
* [.sendPoll(chatId, question, pollOptions, [options])](#TelegramBot+sendPoll) ⇒ <code>Promise</code>
|
||||
* [.stopPoll(chatId, pollId, [options])](#TelegramBot+stopPoll) ⇒ <code>Promise</code>
|
||||
* [.getFile(fileId, [options])](#TelegramBot+getFile) ⇒ <code>Promise</code>
|
||||
* [.getFileLink(fileId, [options])](#TelegramBot+getFileLink) ⇒ <code>Promise</code>
|
||||
* [.getFileStream(fileId, [options])](#TelegramBot+getFileStream) ⇒ <code>stream.Readable</code>
|
||||
@ -393,7 +395,7 @@ Send Document
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**See**
|
||||
|
||||
- https://core.telegram.org/bots/api#senddocument
|
||||
- https://core.telegram.org/bots/api#sendDocument
|
||||
- https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md#sending-files
|
||||
|
||||
|
||||
@ -886,6 +888,37 @@ Use this method to send phone contacts.
|
||||
| firstName | <code>String</code> | Contact's first name |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+sendPoll"></a>
|
||||
|
||||
### telegramBot.sendPoll(chatId, question, pollOptions, [options]) ⇒ <code>Promise</code>
|
||||
Send poll.
|
||||
Use this method to send a native poll.
|
||||
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**See**: https://core.telegram.org/bots/api#sendpoll
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| chatId | <code>Number</code> \| <code>String</code> | Unique identifier for the group/channel |
|
||||
| question | <code>String</code> | Poll question, 255 char limit |
|
||||
| pollOptions | <code>Array</code> | Poll options, between 2-10 options |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+stopPoll"></a>
|
||||
|
||||
### telegramBot.stopPoll(chatId, pollId, [options]) ⇒ <code>Promise</code>
|
||||
Stop poll.
|
||||
Use this method to stop a native poll.
|
||||
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**See**: https://core.telegram.org/bots/api#stoppoll
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| chatId | <code>Number</code> \| <code>String</code> | Unique identifier for the group/channel |
|
||||
| pollId | <code>Number</code> | Identifier of the original message with the poll |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+getFile"></a>
|
||||
|
||||
### telegramBot.getFile(fileId, [options]) ⇒ <code>Promise</code>
|
||||
|
@ -17,7 +17,7 @@ that emits the following events:
|
||||
`sticker`, `video`, `voice`, `contact`, `location`,
|
||||
`new_chat_members`, `left_chat_member`, `new_chat_title`,
|
||||
`new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
|
||||
`game`, `pinned_message`, `migrate_from_chat_id`, `migrate_to_chat_id`,
|
||||
`game`, `pinned_message`, `poll`, `migrate_from_chat_id`, `migrate_to_chat_id`,
|
||||
`channel_chat_created`, `supergroup_chat_created`,
|
||||
`successful_payment`, `invoice`, `video_note`
|
||||
1. **Arguments**: `message` ([Message][message]), `metadata` (`{ type?:string }`)
|
||||
@ -34,6 +34,7 @@ that emits the following events:
|
||||
1. `edited_channel_post_caption`
|
||||
1. `shipping_query`: Received a new incoming shipping query
|
||||
1. `pre_checkout_query`: Received a new incoming pre-checkout query
|
||||
1. `poll`: Received a new incoming poll
|
||||
1. `polling_error`: Error occurred during polling. See [polling errors](#polling-errors).
|
||||
1. `webhook_error`: Error occurred handling a webhook request. See [webhook errors](#webhook-errors).
|
||||
1. `error`: Unexpected error occurred, usually fatal!
|
||||
|
@ -40,6 +40,7 @@ const _messageTypes = [
|
||||
'passport_data',
|
||||
'photo',
|
||||
'pinned_message',
|
||||
'poll',
|
||||
'sticker',
|
||||
'successful_payment',
|
||||
'supergroup_chat_created',
|
||||
@ -586,6 +587,7 @@ class TelegramBot extends EventEmitter {
|
||||
const callbackQuery = update.callback_query;
|
||||
const shippingQuery = update.shipping_query;
|
||||
const preCheckoutQuery = update.pre_checkout_query;
|
||||
const poll = update.poll;
|
||||
|
||||
if (message) {
|
||||
debug('Process Update message %j', message);
|
||||
@ -663,6 +665,9 @@ class TelegramBot extends EventEmitter {
|
||||
} else if (preCheckoutQuery) {
|
||||
debug('Process Update pre_checkout_query %j', preCheckoutQuery);
|
||||
this.emit('pre_checkout_query', preCheckoutQuery);
|
||||
} else if (poll) {
|
||||
debug('Process Update poll %j', poll);
|
||||
this.emit('poll', poll);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1370,6 +1375,39 @@ class TelegramBot extends EventEmitter {
|
||||
return this._request('sendContact', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Send poll.
|
||||
* Use this method to send a native poll.
|
||||
*
|
||||
* @param {Number|String} chatId Unique identifier for the group/channel
|
||||
* @param {String} question Poll question, 255 char limit
|
||||
* @param {Array} pollOptions Poll options, between 2-10 options
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @return {Promise}
|
||||
* @see https://core.telegram.org/bots/api#sendpoll
|
||||
*/
|
||||
sendPoll(chatId, question, pollOptions, form = {}) {
|
||||
form.chat_id = chatId;
|
||||
form.question = question;
|
||||
form.options = stringify(pollOptions);
|
||||
return this._request('sendPoll', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop poll.
|
||||
* Use this method to stop a native poll.
|
||||
*
|
||||
* @param {Number|String} chatId Unique identifier for the group/channel
|
||||
* @param {Number} pollId Identifier of the original message with the poll
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @return {Promise}
|
||||
* @see https://core.telegram.org/bots/api#stoppoll
|
||||
*/
|
||||
stopPoll(chatId, pollId, form = {}) {
|
||||
form.chat_id = chatId;
|
||||
form.message_id = pollId;
|
||||
return this._request('stopPoll', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file.
|
||||
|
Loading…
x
Reference in New Issue
Block a user