mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-31 06:16:07 +00:00
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
This commit is contained in:
committed by
GitHub
parent
f97cad7588
commit
d28875154c
@@ -29,6 +29,7 @@ const USERID = process.env.TEST_USER_ID || 777000;
|
||||
const GROUPID = process.env.TEST_GROUP_ID || -1001075450562;
|
||||
const GAME_SHORT_NAME = process.env.TEST_GAME_SHORT_NAME || 'medusalab_test';
|
||||
const STICKER_SET_NAME = process.env.TEST_STICKER_SET_NAME || 'pusheen';
|
||||
const CURRENT_TIMESTAMP = Date.now();
|
||||
const timeout = 60 * 1000;
|
||||
let portindex = 8091;
|
||||
const staticPort = portindex++;
|
||||
@@ -47,6 +48,7 @@ const FILE_PATH = `${__dirname}/data/photo.png`;
|
||||
let FILE_ID;
|
||||
let GAME_CHAT_ID;
|
||||
let GAME_MSG_ID;
|
||||
let BOT_USERNAME;
|
||||
|
||||
before(function beforeAll() {
|
||||
utils.startStaticServer(staticPort);
|
||||
@@ -112,6 +114,10 @@ describe('TelegramBot', function telegramSuite() {
|
||||
return bot.sendGame(USERID, GAME_SHORT_NAME);
|
||||
}).then(resp => {
|
||||
GAME_MSG_ID = resp.message_id;
|
||||
}).then(() => {
|
||||
return bot.getMe().then(resp => {
|
||||
BOT_USERNAME = resp.username;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -152,7 +158,7 @@ describe('TelegramBot', function telegramSuite() {
|
||||
myBot.on('polling_error', (error) => {
|
||||
assert.ifError(error);
|
||||
});
|
||||
return myBot.setWebHook(ip).then(() => {
|
||||
return myBot.setWebHook(ip, {}).then(() => {
|
||||
return myBot.startPolling();
|
||||
}).then(() => {
|
||||
return myBot.stopPolling();
|
||||
@@ -395,7 +401,7 @@ describe('TelegramBot', function telegramSuite() {
|
||||
});
|
||||
it('should set a webHook', function test() {
|
||||
return bot
|
||||
.setWebHook(ip)
|
||||
.setWebHook(ip, {})
|
||||
.then(resp => {
|
||||
assert.strictEqual(resp, true);
|
||||
});
|
||||
@@ -416,7 +422,7 @@ describe('TelegramBot', function telegramSuite() {
|
||||
});
|
||||
it('should delete the webHook', function test() {
|
||||
return bot
|
||||
.setWebHook('')
|
||||
.setWebHook('', {})
|
||||
.then(resp => {
|
||||
assert.strictEqual(resp, true);
|
||||
});
|
||||
@@ -605,6 +611,16 @@ describe('TelegramBot', function telegramSuite() {
|
||||
assert.ok(is.object(resp.audio));
|
||||
});
|
||||
});
|
||||
it('should send an audio file with thumb', function test() {
|
||||
const audio = `${__dirname}/data/audio.mp3`;
|
||||
const thumbImg = `attach://${__dirname}/data/sticker_thumb.png`;
|
||||
|
||||
return bot.sendAudio(USERID, audio, { thumb: thumbImg }).then(resp => {
|
||||
assert.ok(is.object(resp));
|
||||
assert.ok(is.object(resp.audio));
|
||||
assert.ok(is.object(resp.audio.thumb));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#sendDocument', function sendDocumentSuite() {
|
||||
@@ -740,7 +756,7 @@ describe('TelegramBot', function telegramSuite() {
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('#sendVideoNote', function sendVideoNoteSuite() {
|
||||
describe('#sendVideoNote', function sendVideoNoteSuite() {
|
||||
let videoNoteId;
|
||||
this.timeout(timeout);
|
||||
before(function before() {
|
||||
@@ -750,8 +766,8 @@ describe('TelegramBot', function telegramSuite() {
|
||||
const video = `${__dirname}/data/video.mp4`;
|
||||
return bot.sendVideoNote(USERID, video, { length: 5 }).then(resp => {
|
||||
assert.ok(is.object(resp));
|
||||
assert.ok(is.object(resp.video_note));
|
||||
videoNoteId = resp.video_note.file_id;
|
||||
assert.ok(is.object(resp.video));
|
||||
videoNoteId = resp.video.file_id;
|
||||
});
|
||||
});
|
||||
it('should send a video from id', function test() {
|
||||
@@ -759,21 +775,21 @@ describe('TelegramBot', function telegramSuite() {
|
||||
assert.ok(videoNoteId);
|
||||
return bot.sendVideoNote(USERID, videoNoteId, { length: 5 }).then(resp => {
|
||||
assert.ok(is.object(resp));
|
||||
assert.ok(is.object(resp.video_note));
|
||||
assert.ok(is.object(resp.video));
|
||||
});
|
||||
});
|
||||
it('should send a video from fs.readStream', function test() {
|
||||
const video = fs.createReadStream(`${__dirname}/data/video.mp4`);
|
||||
return bot.sendVideoNote(USERID, video, { length: 5 }).then(resp => {
|
||||
assert.ok(is.object(resp));
|
||||
assert.ok(is.object(resp.video_note));
|
||||
assert.ok(is.object(resp.video));
|
||||
});
|
||||
});
|
||||
it('should send a video from a Buffer', function test() {
|
||||
const video = fs.readFileSync(`${__dirname}/data/video.mp4`);
|
||||
return bot.sendVideoNote(USERID, video, { length: 5 }).then(resp => {
|
||||
assert.ok(is.object(resp));
|
||||
assert.ok(is.object(resp.video_note));
|
||||
assert.ok(is.object(resp.video));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -879,7 +895,7 @@ describe('TelegramBot', function telegramSuite() {
|
||||
|
||||
describe('#getChatMenuButton', function getChatMenuButtonSuite() {
|
||||
it('should get chat menu button', function test() {
|
||||
return bot.getChatMenuButton().then(resp => {
|
||||
return bot.getChatMenuButton({ chat_id: USERID }).then(resp => {
|
||||
assert.ok(is.equal(resp, {
|
||||
type: 'web_app',
|
||||
text: 'Hello',
|
||||
@@ -1589,10 +1605,48 @@ describe('TelegramBot', function telegramSuite() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#createInvoiceLink', function createInvoiceLinkSuite() {
|
||||
before(function before() {
|
||||
utils.handleRatelimit(bot, 'createInvoiceLink', this);
|
||||
});
|
||||
it('should create an invoice link', function test() {
|
||||
if (isCI) {
|
||||
this.skip(); // Skip test for now
|
||||
}
|
||||
const title = 'Invoice link product';
|
||||
const description = 'Our test invoice link product';
|
||||
const payload = 'sku-p002';
|
||||
const providerToken = PROVIDER_TOKEN;
|
||||
const currency = 'EUR';
|
||||
const prices = [{ label: 'NTBA API', amount: 12000 }, { label: 'tax', amount: 10000 }];
|
||||
return bot.createInvoiceLink(title, description, payload, providerToken, currency, prices).then(resp => {
|
||||
console.log(resp);
|
||||
assert.ok(is.string(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('#answerShippingQuery', function answerShippingQuerySuite() { });
|
||||
|
||||
describe.skip('#answerPreCheckoutQuery', function answerPreCheckoutQuerySuite() { });
|
||||
|
||||
describe('#createNewStickerSet', function createNewStickerSetSuite() {
|
||||
before(function before() {
|
||||
utils.handleRatelimit(bot, 'createNewStickerSet', this);
|
||||
});
|
||||
|
||||
it('should create a new sticker set', function test(done) {
|
||||
const sticker = `${__dirname}/data/sticker.png`;
|
||||
const stickerPackName = `s${CURRENT_TIMESTAMP}_by_${BOT_USERNAME}`;
|
||||
|
||||
bot.createNewStickerSet(USERID, stickerPackName, 'Sticker Pack Title', sticker, '😍').then((resp) => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
setTimeout(() => done(), 2000);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('#getStickerSet', function getStickerSetSuite() {
|
||||
before(function before() {
|
||||
utils.handleRatelimit(bot, 'getStickerSet', this);
|
||||
@@ -1606,6 +1660,31 @@ describe('TelegramBot', function telegramSuite() {
|
||||
assert.ok(is.array(resp.stickers));
|
||||
});
|
||||
});
|
||||
it('should get the recent sticker set created given the name of the set', function test() {
|
||||
const stickerPackName = `s${CURRENT_TIMESTAMP}_by_${BOT_USERNAME}`;
|
||||
return bot.getStickerSet(stickerPackName).then(resp => {
|
||||
assert.ok(is.object(resp));
|
||||
assert.strictEqual(resp.name.toLowerCase(), stickerPackName.toLowerCase());
|
||||
assert.ok(is.string(resp.title));
|
||||
assert.ok(is.boolean(resp.contains_masks));
|
||||
assert.ok(is.array(resp.stickers));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setStickerSetThumb', function setStickerSetThumbSuite() {
|
||||
before(function before() {
|
||||
utils.handleRatelimit(bot, 'setStickerSetThumb', this);
|
||||
});
|
||||
|
||||
it('should set a sticker set thumb', function test() {
|
||||
const stickerThumb = `${__dirname}/data/sticker_thumb.png`;
|
||||
const stickerPackName = `s${CURRENT_TIMESTAMP}_by_${BOT_USERNAME}`;
|
||||
|
||||
bot.setStickerSetThumb(USERID, stickerPackName, stickerThumb).then((resp) => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#uploadStickerFile', function sendPhotoSuite() {
|
||||
|
Reference in New Issue
Block a user