mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-31 06:16:07 +00:00
Add new method sendDice, getMyCommands, setMyCommands and more (#796)
* Add new method sendPoll * getMyCommands * setMyCommands * Update doc/api * 1# Fix Test sendPhoto The sendPhoto method does not support .gif files, use sendAnimation. This fix remplace .gif file by .png * CustomTitle and ChatPermissions support setChatAdministratorCustomTitle setChatPermissions * Update Readme Update Badge Telegram API Version * Minor Fix and Fix setChatPhoto The Telegram Bots api has a bug that they are fixing and gives problems with the previous image. While they don't fix it, the image replacement is the fastest solution * Minor Fix and Add Test Fixed setChatPermissions Test: - sendDice - getMyCommands - setMyCommands - setChatAdministratorCustomTitle - setChatPermissions * Update Changelog and Package.json version * Fix typos in Changelog * Add support for poll_answer From: https://github.com/yagop/node-telegram-bot-api/pull/777 * Add JieJiSS contribution in Changelog * Add sendPoll Test
This commit is contained in:
committed by
GitHub
parent
c6a0eedc9a
commit
1bae9c2964
124
test/telegram.js
124
test/telegram.js
@@ -43,7 +43,7 @@ const cert = `${__dirname}/../examples/ssl/crt.pem`;
|
||||
const ip = '216.58.210.174'; // Google IP ¯\_(ツ)_/¯
|
||||
const lat = 47.5351072;
|
||||
const long = -52.7508537;
|
||||
const FILE_PATH = `${__dirname}/data/photo.gif`;
|
||||
const FILE_PATH = `${__dirname}/data/photo.png`;
|
||||
let FILE_ID;
|
||||
let GAME_CHAT_ID;
|
||||
let GAME_MSG_ID;
|
||||
@@ -481,7 +481,7 @@ describe('TelegramBot', function telegramSuite() {
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('#answerInlineQuery', function answerInlineQuerySuite() {});
|
||||
describe.skip('#answerInlineQuery', function answerInlineQuerySuite() { });
|
||||
|
||||
describe('#forwardMessage', function forwardMessageSuite() {
|
||||
before(function before() {
|
||||
@@ -507,7 +507,7 @@ describe('TelegramBot', function telegramSuite() {
|
||||
utils.handleRatelimit(bot, 'sendPhoto', this);
|
||||
});
|
||||
it('should send a photo from file', function test() {
|
||||
const photo = `${__dirname}/data/photo.gif`;
|
||||
const photo = `${__dirname}/data/photo.png`;
|
||||
return bot.sendPhoto(USERID, photo).then(resp => {
|
||||
assert.ok(is.object(resp));
|
||||
assert.ok(is.array(resp.photo));
|
||||
@@ -523,21 +523,21 @@ describe('TelegramBot', function telegramSuite() {
|
||||
});
|
||||
});
|
||||
it('should send a photo from fs.readStream', function test() {
|
||||
const photo = fs.createReadStream(`${__dirname}/data/photo.gif`);
|
||||
const photo = fs.createReadStream(`${__dirname}/data/photo.png`);
|
||||
return bot.sendPhoto(USERID, photo).then(resp => {
|
||||
assert.ok(is.object(resp));
|
||||
assert.ok(is.array(resp.photo));
|
||||
});
|
||||
});
|
||||
it('should send a photo from request Stream', function test() {
|
||||
const photo = request(`${staticUrl}/photo.gif`);
|
||||
const photo = request(`${staticUrl}/photo.png`);
|
||||
return bot.sendPhoto(USERID, photo).then(resp => {
|
||||
assert.ok(is.object(resp));
|
||||
assert.ok(is.array(resp.photo));
|
||||
});
|
||||
});
|
||||
it('should send a photo from a Buffer', function test() {
|
||||
const photo = fs.readFileSync(`${__dirname}/data/photo.gif`);
|
||||
const photo = fs.readFileSync(`${__dirname}/data/photo.png`);
|
||||
return bot.sendPhoto(USERID, photo).then(resp => {
|
||||
assert.ok(is.object(resp));
|
||||
assert.ok(is.array(resp.photo));
|
||||
@@ -817,15 +817,61 @@ describe('TelegramBot', function telegramSuite() {
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('#kickChatMember', function kickChatMemberSuite() {});
|
||||
describe.skip('#kickChatMember', function kickChatMemberSuite() { });
|
||||
|
||||
describe.skip('#unbanChatMember', function unbanChatMemberSuite() {});
|
||||
describe.skip('#unbanChatMember', function unbanChatMemberSuite() { });
|
||||
|
||||
describe.skip('#restrictChatMember', function restrictChatMemberSuite() {});
|
||||
describe.skip('#restrictChatMember', function restrictChatMemberSuite() { });
|
||||
|
||||
describe.skip('#promoteChatMember', function promoteChatMemberSuite() {});
|
||||
describe.skip('#promoteChatMember', function promoteChatMemberSuite() { });
|
||||
|
||||
describe.skip('#answerCallbackQuery', function answerCallbackQuerySuite() {});
|
||||
describe.skip('#answerCallbackQuery', function answerCallbackQuerySuite() { });
|
||||
|
||||
describe('#setMyCommands', function setMyCommandsSuite() {
|
||||
it('should set bot commands', function test() {
|
||||
const opts = [
|
||||
{ command: 'eat', description: 'Command for eat' },
|
||||
{ command: 'run', description: 'Command for run' }
|
||||
];
|
||||
return bot.setMyCommands(opts).then(resp => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getMyCommands ', function getMyCommandsSuite() {
|
||||
it('should get bot commands', function test() {
|
||||
return bot.getMyCommands().then(resp => {
|
||||
assert.ok(is.array(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('#setChatAdministratorCustomTitle ', function setChatAdministratorCustomTitleSuite() {
|
||||
it('should set chat permissions', function test() {
|
||||
return bot.setChatAdministratorCustomTitle(GROUPID, USERID, 'Custom Name').then(resp => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setChatPermissions ', function setChatPermissionsSuite() {
|
||||
it('should set chat permissions', function test() {
|
||||
const ChatPermissions = {
|
||||
can_send_messages: true,
|
||||
can_send_media_messages: true,
|
||||
can_send_polls: false,
|
||||
can_send_other_messages: false,
|
||||
can_add_web_page_previews: true,
|
||||
can_change_info: false,
|
||||
can_invite_users: false,
|
||||
can_pin_messages: true
|
||||
};
|
||||
return bot.setChatPermissions(GROUPID, ChatPermissions).then(resp => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#exportChatInviteLink', function exportChatInviteLinkSuite() {
|
||||
before(function before() {
|
||||
@@ -885,7 +931,8 @@ describe('TelegramBot', function telegramSuite() {
|
||||
utils.handleRatelimit(bot, 'setChatTitle', this);
|
||||
});
|
||||
it('should set the chat title', function test() {
|
||||
return bot.setChatTitle(GROUPID, 'ntba test group').then(resp => {
|
||||
const random = Math.floor(Math.random() * 1000);
|
||||
return bot.setChatTitle(GROUPID, `ntba test group (random: ${random})`).then(resp => {
|
||||
assert.equal(resp, true);
|
||||
});
|
||||
});
|
||||
@@ -956,7 +1003,7 @@ describe('TelegramBot', function telegramSuite() {
|
||||
utils.handleRatelimit(bot, 'editMessageCaption', this);
|
||||
});
|
||||
it('should edit a caption sent by the bot', function test() {
|
||||
const photo = `${__dirname}/data/photo.gif`;
|
||||
const photo = `${__dirname}/data/photo.png`;
|
||||
const options = { caption: 'test caption' };
|
||||
return bot.sendPhoto(USERID, photo, options).then(resp => {
|
||||
assert.equal(resp.caption, 'test caption');
|
||||
@@ -1128,6 +1175,43 @@ describe('TelegramBot', function telegramSuite() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#sendPoll', function sendPollSuite() {
|
||||
it('should send a Poll', function test() {
|
||||
const question = '¿Are you okey?';
|
||||
const answers = ['Yes', 'No'];
|
||||
const opts = { is_anonymous: true };
|
||||
return bot.sendPoll(GROUPID, question, answers, opts).then(resp => {
|
||||
assert.ok(is.object(resp));
|
||||
});
|
||||
});
|
||||
it('should send a Quiz', function test() {
|
||||
const question = '¿Are you okey?';
|
||||
const answers = ['Yes', 'No'];
|
||||
const opts = {
|
||||
is_anonymous: true,
|
||||
type: 'quiz',
|
||||
correct_option_id: 0
|
||||
};
|
||||
return bot.sendPoll(GROUPID, question, answers, opts).then(resp => {
|
||||
assert.ok(is.object(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#sendDice', function sendDiceSuite() {
|
||||
it('should send a Dice', function test() {
|
||||
return bot.sendDice(GROUPID).then(resp => {
|
||||
assert.ok(is.object(resp));
|
||||
});
|
||||
});
|
||||
it('should send a Dart', function test() {
|
||||
const opts = { emoji: '🎯' };
|
||||
return bot.sendDice(GROUPID, opts).then(resp => {
|
||||
assert.ok(is.object(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getFile', function getFileSuite() {
|
||||
this.timeout(timeout);
|
||||
before(function before() {
|
||||
@@ -1221,7 +1305,7 @@ describe('TelegramBot', function telegramSuite() {
|
||||
describe('#removeTextListener', function removeTextListenerSuite() {
|
||||
const regexp = /\/onText/;
|
||||
const regexp2 = /\/onText/;
|
||||
const callback = function noop() {};
|
||||
const callback = function noop() { };
|
||||
after(function after() {
|
||||
bot.removeTextListener(regexp);
|
||||
bot.removeTextListener(regexp2);
|
||||
@@ -1240,12 +1324,12 @@ describe('TelegramBot', function telegramSuite() {
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('#onReplyToMessage', function onReplyToMessageSuite() {});
|
||||
describe.skip('#onReplyToMessage', function onReplyToMessageSuite() { });
|
||||
|
||||
describe('#removeReplyListener', function removeReplyListenerSuite() {
|
||||
const chatId = -1234;
|
||||
const messageId = 1;
|
||||
const callback = function noop() {};
|
||||
const callback = function noop() { };
|
||||
it('returns the right reply-listener', function test() {
|
||||
const id = bot.onReplyToMessage(chatId, messageId, callback);
|
||||
const replyListener = bot.removeReplyListener(id);
|
||||
@@ -1306,7 +1390,7 @@ describe('TelegramBot', function telegramSuite() {
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('#leaveChat', function leaveChatSuite() {});
|
||||
describe.skip('#leaveChat', function leaveChatSuite() { });
|
||||
|
||||
describe('#sendGame', function sendGameSuite() {
|
||||
before(function before() {
|
||||
@@ -1375,9 +1459,9 @@ describe('TelegramBot', function telegramSuite() {
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('#answerShippingQuery', function answerShippingQuerySuite() {});
|
||||
describe.skip('#answerShippingQuery', function answerShippingQuerySuite() { });
|
||||
|
||||
describe.skip('#answerPreCheckoutQuery', function answerPreCheckoutQuerySuite() {});
|
||||
describe.skip('#answerPreCheckoutQuery', function answerPreCheckoutQuerySuite() { });
|
||||
|
||||
describe('#getStickerSet', function getStickerSetSuite() {
|
||||
before(function before() {
|
||||
@@ -1416,7 +1500,7 @@ describe('TelegramBot', function telegramSuite() {
|
||||
return bot.sendMediaGroup(USERID, [
|
||||
{
|
||||
type: 'photo',
|
||||
media: `${__dirname}/data/photo.gif`,
|
||||
media: `${__dirname}/data/photo.png`,
|
||||
},
|
||||
{
|
||||
type: 'video',
|
||||
|
Reference in New Issue
Block a user