Skip to content

Commit

Permalink
Add new method sendDice, getMyCommands, setMyCommands and more (#796)
Browse files Browse the repository at this point in the history
* 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: #777

* Add JieJiSS contribution in Changelog

* Add sendPoll Test
  • Loading branch information
danielperez9430 committed May 12, 2020
1 parent c6a0eed commit 1bae9c2
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 177 deletions.
24 changes: 23 additions & 1 deletion CHANGELOG.md
Expand Up @@ -3,7 +3,29 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.40.0][0.40.0] - 2019-10-15
## [0.50.0][0.50.0] - 2020-05-2020
1. Support Bot API v4.8: (by @danielperez9430)
* Add methods: *sendDice()*
1. Support Bot API v4.7: (by @danielperez9430)
* Add methods: *getMyCommands()*,*setMyCommands()*
1. Support Bot API v4.5: (by @danielperez9430)
* Add methods: *setChatAdministratorCustomTitle()*
1. Support Bot API v4.4: (by @danielperez9430)
* Add methods: *setChatPermissions()*
1. Support for poll_answer (by @JieJiSS)

Changed: (by @danielperez9430)
* New message type: *dice*
* Fix Bugs in tests

New Test: (by @danielperez9430)
* sendDice
* getMyCommands
* setMyCommands
* setChatAdministratorCustomTitle
* setChatPermissions

## [0.40.0][0.40.0] - 2019-05-04

Added:

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -4,7 +4,7 @@

Node.js module to interact with the official [Telegram Bot API](https://core.telegram.org/bots/api).

[![Bot API](https://img.shields.io/badge/Bot%20API-v.4.4.0-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api)
[![Bot API](https://img.shields.io/badge/Bot%20API-v.4.8.0-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api)
[![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)
[![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)
[![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)
Expand Down
384 changes: 231 additions & 153 deletions doc/api.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc/usage.md
Expand Up @@ -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`, `poll`, `migrate_from_chat_id`, `migrate_to_chat_id`,
`game`, `pinned_message`, `poll`, `dice`, `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 }`)
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "node-telegram-bot-api",
"version": "0.40.0",
"version": "0.50.0",
"description": "Telegram Bot API",
"main": "./index.js",
"directories": {
Expand Down
86 changes: 86 additions & 0 deletions src/telegram.js
Expand Up @@ -26,6 +26,7 @@ const _messageTypes = [
'channel_chat_created',
'contact',
'delete_chat_photo',
'dice',
'document',
'game',
'group_chat_created',
Expand Down Expand Up @@ -588,6 +589,7 @@ class TelegramBot extends EventEmitter {
const shippingQuery = update.shipping_query;
const preCheckoutQuery = update.pre_checkout_query;
const poll = update.poll;
const pollAnswer = update.poll_answer;

if (message) {
debug('Process Update message %j', message);
Expand Down Expand Up @@ -668,6 +670,9 @@ class TelegramBot extends EventEmitter {
} else if (poll) {
debug('Process Update poll %j', poll);
this.emit('poll', poll);
} else if (pollAnswer) {
debug('Process Update poll_answer %j', pollAnswer);
this.emit('poll_answer', pollAnswer);
}
}

Expand Down Expand Up @@ -767,6 +772,28 @@ class TelegramBot extends EventEmitter {
return this._request('sendAudio', opts);
}

/**
* Send Dice
* Use this method to send a dice.
* @param {Number|String} chatId Unique identifier for the message recipient
* @param {Object} [options] Additional Telegram query options
* @return {Promise}
* @see https://core.telegram.org/bots/api#senddice
*/
sendDice(chatId, options = {}) {
const opts = {
qs: options,
};
opts.qs.chat_id = chatId;
try {
const sendData = this._formatSendData('dice');
opts.formData = sendData[0];
} catch (ex) {
return Promise.reject(ex);
}
return this._request('sendDice', opts);
}

/**
* Send Document
* @param {Number|String} chatId Unique identifier for the message recipient
Expand Down Expand Up @@ -1016,6 +1043,42 @@ class TelegramBot extends EventEmitter {
return this._request('promoteChatMember', { form });
}

/**
* Use this method to set a custom title for an administrator in a supergroup promoted by the bot.
* Returns True on success.
*
* @param {Number|String} chatId Unique identifier for the message recipient
* @param {Number} userId Unique identifier of the target user
* @param {String} customTitle New custom title for the administrator; 0-16 characters, emoji are not allowed
* @param {Object} [options] Additional Telegram query options
* @return {Promise}
* @see https://core.telegram.org/bots/api#setchatadministratorcustomtitle
*/
setChatAdministratorCustomTitle(chatId, userId, customTitle, form = {}) {
form.chat_id = chatId;
form.user_id = userId;
form.custom_title = customTitle;
return this._request('setChatAdministratorCustomTitle', { form });
}

/**
* Use this method to set default chat permissions for all members.
* The bot must be an administrator in the group or a supergroup for this to
* work and must have the can_restrict_members admin rights.
* Returns True on success.
*
* @param {Number|String} chatId Unique identifier for the message recipient
* @param {Array} chatPermissions New default chat permissions
* @param {Object} [options] Additional Telegram query options
* @return {Promise}
* @see https://core.telegram.org/bots/api#setchatpermissions
*/
setChatPermissions(chatId, chatPermissions, form = {}) {
form.chat_id = chatId;
form.permissions = JSON.stringify(chatPermissions);
return this._request('setChatPermissions', { form });
}

/**
* Use this method to export an invite link to a supergroup or a channel.
* The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Expand Down Expand Up @@ -1181,6 +1244,29 @@ class TelegramBot extends EventEmitter {
return this._request('answerCallbackQuery', { form });
}

/**
* Returns True on success.
* Use this method to change the list of the bot's commands.
* @param {Array} commands Poll options, between 2-10 options
* @param {Object} [options] Additional Telegram query options
* @return {Promise}
* @see https://core.telegram.org/bots/api#setmycommands
*/
setMyCommands(commands, form = {}) {
form.commands = stringify(commands);
return this._request('setMyCommands', { form });
}

/**
* Returns Array of BotCommand on success.
* @param {Object} [options] Additional Telegram query options
* @return {Promise}
* @see https://core.telegram.org/bots/api#getmycommands
*/
getMyCommands(form = {}) {
return this._request('getMyCommands', { form });
}

/**
* Use this method to edit text messages sent by the bot or via
* the bot (for inline bots). On success, the edited Message is
Expand Down
Binary file modified test/data/chat_photo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/data/photo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1bae9c2

Please sign in to comment.