diff --git a/CHANGELOG.md b/CHANGELOG.md
index 23349cc7..04d651fe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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*
* * *
diff --git a/doc/api.md b/doc/api.md
index fddbcdc4..ea9bd69c 100644
--- a/doc/api.md
+++ b/doc/api.md
@@ -61,6 +61,8 @@ TelegramBot
* [.stopMessageLiveLocation([options])](#TelegramBot+stopMessageLiveLocation) ⇒ Promise
* [.sendVenue(chatId, latitude, longitude, title, address, [options])](#TelegramBot+sendVenue) ⇒ Promise
* [.sendContact(chatId, phoneNumber, firstName, [options])](#TelegramBot+sendContact) ⇒ Promise
+ * [.sendPoll(chatId, question, pollOptions, [options])](#TelegramBot+sendPoll) ⇒ Promise
+ * [.stopPoll(chatId, pollId, [options])](#TelegramBot+stopPoll) ⇒ Promise
* [.getFile(fileId, [options])](#TelegramBot+getFile) ⇒ Promise
* [.getFileLink(fileId, [options])](#TelegramBot+getFileLink) ⇒ Promise
* [.getFileStream(fileId, [options])](#TelegramBot+getFileStream) ⇒ stream.Readable
@@ -393,7 +395,7 @@ Send Document
**Kind**: instance method of [TelegramBot
](#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 | String
| Contact's first name |
| [options] | Object
| Additional Telegram query options |
+
+
+### telegramBot.sendPoll(chatId, question, pollOptions, [options]) ⇒ Promise
+Send poll.
+Use this method to send a native poll.
+
+**Kind**: instance method of [TelegramBot
](#TelegramBot)
+**See**: https://core.telegram.org/bots/api#sendpoll
+
+| Param | Type | Description |
+| --- | --- | --- |
+| chatId | Number
\| String
| Unique identifier for the group/channel |
+| question | String
| Poll question, 255 char limit |
+| pollOptions | Array
| Poll options, between 2-10 options |
+| [options] | Object
| Additional Telegram query options |
+
+
+
+### telegramBot.stopPoll(chatId, pollId, [options]) ⇒ Promise
+Stop poll.
+Use this method to stop a native poll.
+
+**Kind**: instance method of [TelegramBot
](#TelegramBot)
+**See**: https://core.telegram.org/bots/api#stoppoll
+
+| Param | Type | Description |
+| --- | --- | --- |
+| chatId | Number
\| String
| Unique identifier for the group/channel |
+| pollId | Number
| Identifier of the original message with the poll |
+| [options] | Object
| Additional Telegram query options |
+
### telegramBot.getFile(fileId, [options]) ⇒ Promise
diff --git a/doc/usage.md b/doc/usage.md
index 0bf2527c..b3d30481 100644
--- a/doc/usage.md
+++ b/doc/usage.md
@@ -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!
diff --git a/src/telegram.js b/src/telegram.js
index 9a76bb10..f3a12e45 100644
--- a/src/telegram.js
+++ b/src/telegram.js
@@ -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.