Skip to content

Commit d288751

Browse files
feat: Telegram Bot API 6.1 and bug fixes (#977)
## [0.58.0][0.58.0] - 2022-06-22 1. Support Bot API v6.1: (@danielperez9430) * Add method *createInvoiceLink()* 2. Support for setStickerSetThumb (@elihaidv) 3. Add new test (@danielperez9430) * createInvoiceLink 4. Test fixes (@danielperez9430) * sendVideoNote * createNewStickerSet * setStickerSetThumb * getChatMenuButton * setWebHook 5. Bug fixes (@danielperez9430) * answerWebAppQuery * Support for send thumb in sendAudio
1 parent f97cad7 commit d288751

File tree

8 files changed

+203
-16
lines changed

8 files changed

+203
-16
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,27 @@
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
## [0.58.0][0.58.0] - 2022-06-22
7+
8+
1. Support Bot API v6.1: (@danielperez9430)
9+
* Add method *createInvoiceLink()*
10+
11+
2. Support for setStickerSetThumb (@elihaidv)
12+
13+
3. Add new test (@danielperez9430)
14+
* createInvoiceLink
15+
16+
4. Test fixes (@danielperez9430)
17+
* sendVideoNote
18+
* createNewStickerSet
19+
* setStickerSetThumb
20+
* getChatMenuButton
21+
* setWebHook
22+
23+
5. Bug fixes (@danielperez9430)
24+
* answerWebAppQuery
25+
* Support for send thumb in sendAudio
26+
627
## [0.57.0][0.57.0] - 2022-04-23
728

829
Added:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Node.js module to interact with the official [Telegram Bot API](https://core.telegram.org/bots/api).
66

77

8-
[![Bot API](https://img.shields.io/badge/Bot%20API-v.5.5-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api)
8+
[![Bot API](https://img.shields.io/badge/Bot%20API-v.6.1-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api)
99
[![npm package](https://img.shields.io/npm/v/node-telegram-bot-api?logo=npm&style=flat-square)](https://www.npmjs.org/package/node-telegram-bot-api)
1010
[![Build Status](https://img.shields.io/travis/yagop/node-telegram-bot-api/master?style=flat-square&logo=travis)](https://travis-ci.org/yagop/node-telegram-bot-api)
1111
[![Coverage Status](https://img.shields.io/codecov/c/github/yagop/node-telegram-bot-api?style=flat-square&logo=codecov)](https://codecov.io/gh/yagop/node-telegram-bot-api)

doc/api.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,14 @@ TelegramBot
109109
* [.getGameHighScores(userId, [options])](#TelegramBot+getGameHighScores) ⇒ <code>Promise</code>
110110
* [.deleteMessage(chatId, messageId, [options])](#TelegramBot+deleteMessage) ⇒ <code>Promise</code>
111111
* [.sendInvoice(chatId, title, description, payload, providerToken, startParameter, currency, prices, [options])](#TelegramBot+sendInvoice) ⇒ <code>Promise</code>
112+
* [.createInvoiceLink(title, description, payload, providerToken, currency, prices, [options])](#TelegramBot+createInvoiceLink) ⇒ <code>String</code>
112113
* [.answerShippingQuery(shippingQueryId, ok, [options])](#TelegramBot+answerShippingQuery) ⇒ <code>Promise</code>
113114
* [.answerPreCheckoutQuery(preCheckoutQueryId, ok, [options])](#TelegramBot+answerPreCheckoutQuery) ⇒ <code>Promise</code>
114115
* [.getStickerSet(name, [options])](#TelegramBot+getStickerSet) ⇒ <code>Promise</code>
115116
* [.uploadStickerFile(userId, pngSticker, [options], [fileOptions])](#TelegramBot+uploadStickerFile) ⇒ <code>Promise</code>
116117
* [.createNewStickerSet(userId, name, title, pngSticker, emojis, [options], [fileOptions])](#TelegramBot+createNewStickerSet) ⇒ <code>Promise</code>
117118
* [.addStickerToSet(userId, name, pngSticker, emojis, [options], [fileOptions])](#TelegramBot+addStickerToSet) ⇒ <code>Promise</code>
119+
* [.setStickerSetThumb(userId, name, pngThumb, [options], [fileOptions])](#TelegramBot+setStickerSetThumb) ⇒ <code>Promise</code>
118120
* [.setStickerPositionInSet(sticker, position, [options])](#TelegramBot+setStickerPositionInSet) ⇒ <code>Promise</code>
119121
* [.deleteStickerFromSet(sticker, [options])](#TelegramBot+deleteStickerFromSet) ⇒ <code>Promise</code>
120122
* [.sendMediaGroup(chatId, media, [options])](#TelegramBot+sendMediaGroup) ⇒ <code>Promise</code>
@@ -1628,10 +1630,29 @@ Use this method to send an invoice.
16281630
| prices | <code>Array</code> | Breakdown of prices |
16291631
| [options] | <code>Object</code> | Additional Telegram query options |
16301632

1633+
<a name="TelegramBot+createInvoiceLink"></a>
1634+
1635+
### telegramBot.createInvoiceLink(title, description, payload, providerToken, currency, prices, [options]) ⇒ <code>String</code>
1636+
Create Invoice Link
1637+
Use this method to create a link for an invoice. Returns the created invoice link as String on success.
1638+
1639+
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
1640+
**See**: https://core.telegram.org/bots/api#createinvoicelink
1641+
1642+
| Param | Type | Description |
1643+
| --- | --- | --- |
1644+
| title | <code>String</code> | Product name, 1-32 characters |
1645+
| description | <code>String</code> | Product description, 1-255 characters |
1646+
| payload | <code>String</code> | Bot defined invoice payload |
1647+
| providerToken | <code>String</code> | Payment provider token |
1648+
| currency | <code>String</code> | Three-letter ISO 4217 currency code |
1649+
| prices | <code>Array</code> | Breakdown of prices |
1650+
| [options] | <code>Object</code> | Additional Telegram query options |
1651+
16311652
<a name="TelegramBot+answerShippingQuery"></a>
16321653

16331654
### telegramBot.answerShippingQuery(shippingQueryId, ok, [options]) ⇒ <code>Promise</code>
1634-
Answer shipping query..
1655+
Answer shipping query.
16351656
Use this method to reply to shipping queries.
16361657

16371658
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
@@ -1733,6 +1754,27 @@ Returns True on success.
17331754
| [options] | <code>Object</code> | Additional Telegram query options |
17341755
| [fileOptions] | <code>Object</code> | Optional file related meta-data |
17351756

1757+
<a name="TelegramBot+setStickerSetThumb"></a>
1758+
1759+
### telegramBot.setStickerSetThumb(userId, name, pngThumb, [options], [fileOptions]) ⇒ <code>Promise</code>
1760+
Use this method to add a thumb to a set created by the bot.
1761+
Returns True on success.
1762+
1763+
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
1764+
**See**: https://core.telegram.org/bots/api#setstickersetthumb
1765+
**Todo**
1766+
1767+
- [ ] Add tests for this method!
1768+
1769+
1770+
| Param | Type | Description |
1771+
| --- | --- | --- |
1772+
| userId | <code>Number</code> | User identifier of sticker set owner |
1773+
| name | <code>String</code> | Sticker set name |
1774+
| pngThumb | <code>String</code> \| <code>stream.Stream</code> \| <code>Buffer</code> | A PNG image with the thumbnail, must be up to 128 kilobytes in size and have width and height exactly 100px, or a TGS animation with the thumbnail up to 32 kilobytes in size; |
1775+
| [options] | <code>Object</code> | Additional Telegram query options |
1776+
| [fileOptions] | <code>Object</code> | Optional file related meta-data |
1777+
17361778
<a name="TelegramBot+setStickerPositionInSet"></a>
17371779

17381780
### telegramBot.setStickerPositionInSet(sticker, position, [options]) ⇒ <code>Promise</code>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-telegram-bot-api",
3-
"version": "0.57.0",
3+
"version": "0.58.0",
44
"description": "Telegram Bot API",
55
"main": "./index.js",
66
"directories": {

src/telegram.js

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -827,14 +827,35 @@ class TelegramBot extends EventEmitter {
827827
const opts = {
828828
qs: options
829829
};
830+
830831
opts.qs.chat_id = chatId;
832+
831833
try {
832834
const sendData = this._formatSendData('audio', audio, fileOptions);
833835
opts.formData = sendData[0];
834836
opts.qs.audio = sendData[1];
835837
} catch (ex) {
836838
return Promise.reject(ex);
837839
}
840+
841+
if (options.thumb) {
842+
if (opts.formData === null) {
843+
opts.formData = {};
844+
}
845+
846+
try {
847+
const attachName = 'photo';
848+
const [formData] = this._formatSendData(attachName, options.thumb.replace('attach://', ''));
849+
850+
if (formData) {
851+
opts.formData[attachName] = formData[attachName];
852+
opts.qs.thumb = `attach://${attachName}`;
853+
}
854+
} catch (ex) {
855+
return Promise.reject(ex);
856+
}
857+
}
858+
838859
return this._request('sendAudio', opts);
839860
}
840861

@@ -1482,7 +1503,7 @@ class TelegramBot extends EventEmitter {
14821503
answerWebAppQuery(webAppQueryId, result, form = {}) {
14831504
form.web_app_query_id = webAppQueryId;
14841505
form.result = stringify(result);
1485-
return this._request('answerCallbackQuery', { form });
1506+
return this._request('answerWebAppQuery', { form });
14861507
}
14871508

14881509

@@ -2195,7 +2216,31 @@ class TelegramBot extends EventEmitter {
21952216
}
21962217

21972218
/**
2198-
* Answer shipping query..
2219+
* Create Invoice Link
2220+
* Use this method to create a link for an invoice. Returns the created invoice link as String on success.
2221+
*
2222+
* @param {String} title Product name, 1-32 characters
2223+
* @param {String} description Product description, 1-255 characters
2224+
* @param {String} payload Bot defined invoice payload
2225+
* @param {String} providerToken Payment provider token
2226+
* @param {String} currency Three-letter ISO 4217 currency code
2227+
* @param {Array} prices Breakdown of prices
2228+
* @param {Object} [options] Additional Telegram query options
2229+
* @returns {String}
2230+
* @see https://core.telegram.org/bots/api#createinvoicelink
2231+
*/
2232+
createInvoiceLink(title, description, payload, providerToken, currency, prices, form = {}) {
2233+
form.title = title;
2234+
form.description = description;
2235+
form.payload = payload;
2236+
form.provider_token = providerToken;
2237+
form.currency = currency;
2238+
form.prices = stringify(prices);
2239+
return this._request('createInvoiceLink', { form });
2240+
}
2241+
2242+
/**
2243+
* Answer shipping query.
21992244
* Use this method to reply to shipping queries.
22002245
*
22012246
* @param {String} shippingQueryId Unique identifier for the query to be answered
@@ -2335,7 +2380,7 @@ class TelegramBot extends EventEmitter {
23352380
}
23362381
return this._request('addStickerToSet', opts);
23372382
}
2338-
2383+
23392384
/**
23402385
* Use this method to add a thumb to a set created by the bot.
23412386
* Returns True on success.

test/data/sticker.png

-130 KB
Loading

test/data/sticker_thumb.png

14.2 KB
Loading

0 commit comments

Comments
 (0)