mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-28 12:57:38 +00:00
Add accompanying tests, minor fixes and updates for PR #158
This commit is contained in:
parent
628aa5b2d9
commit
f5af2bf588
25
README.md
25
README.md
@ -60,7 +60,6 @@ TelegramBot
|
||||
* [new TelegramBot(token, [options])](#new_TelegramBot_new)
|
||||
* [.stopPolling()](#TelegramBot+stopPolling) ⇒ <code>Promise</code>
|
||||
* [.getMe()](#TelegramBot+getMe) ⇒ <code>Promise</code>
|
||||
* [.getChat(chatId)](#TelegramBot+getChat) ⇒ <code>Promise</code>
|
||||
* [.setWebHook(url, [cert])](#TelegramBot+setWebHook)
|
||||
* [.getUpdates([timeout], [limit], [offset])](#TelegramBot+getUpdates) ⇒ <code>Promise</code>
|
||||
* [.sendMessage(chatId, text, [options])](#TelegramBot+sendMessage) ⇒ <code>Promise</code>
|
||||
@ -125,20 +124,6 @@ Returns basic information about the bot in form of a `User` object.
|
||||
|
||||
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||
**See**: https://core.telegram.org/bots/api#getme
|
||||
<a name="TelegramBot+getChat"></a>
|
||||
|
||||
### telegramBot.getChat(chatId) ⇒ <code>Promise</code>
|
||||
Use this method to get up to date information about the chat
|
||||
(current name of the user for one-on-one conversations, current
|
||||
username of a user, group or channel, etc.).
|
||||
|
||||
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||
**See**: https://core.telegram.org/bots/api#getchat
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| chatId | <code>Number</code> | <code>String</code> | Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) |
|
||||
|
||||
<a name="TelegramBot+setWebHook"></a>
|
||||
|
||||
### telegramBot.setWebHook(url, [cert])
|
||||
@ -538,14 +523,16 @@ Register a reply to wait for a message response.
|
||||
<a name="TelegramBot+getChat"></a>
|
||||
|
||||
### telegramBot.getChat(chatId) ⇒ <code>Promise</code>
|
||||
Returns information about the chat in form of a `Chat` object.
|
||||
Use this method to get up to date information about the chat
|
||||
(current name of the user for one-on-one conversations, current
|
||||
username of a user, group or channel, etc.).
|
||||
|
||||
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||
**See**: https://core.telegram.org/bots/api#getchat
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| chatId | <code>Number</code> | <code>String</code> | Unique identifier for the target group or username of the target supergroup |
|
||||
| chatId | <code>Number</code> | <code>String</code> | Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) |
|
||||
|
||||
<a name="TelegramBot+getChatAdministrators"></a>
|
||||
|
||||
@ -562,7 +549,7 @@ Returns the administrators in a chat in form of an Array of `ChatMember` objects
|
||||
<a name="TelegramBot+getChatMembersCount"></a>
|
||||
|
||||
### telegramBot.getChatMembersCount(chatId) ⇒ <code>Promise</code>
|
||||
Returns the number of members in a chat in form of an `Int` object.
|
||||
Use this method to get the number of members in a chat.
|
||||
|
||||
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||
**See**: https://core.telegram.org/bots/api#getchatmemberscount
|
||||
@ -574,7 +561,7 @@ Returns the number of members in a chat in form of an `Int` object.
|
||||
<a name="TelegramBot+getChatMember"></a>
|
||||
|
||||
### telegramBot.getChatMember(chatId, userId) ⇒ <code>Promise</code>
|
||||
Returns information about a member of a chat in form of a `ChatMember` object.
|
||||
Use this method to get information about a member of a chat.
|
||||
|
||||
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||
**See**: https://core.telegram.org/bots/api#getchatmember
|
||||
|
@ -205,21 +205,6 @@ class TelegramBot extends EventEmitter {
|
||||
return this._request(_path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to get up to date information about the chat
|
||||
* (current name of the user for one-on-one conversations, current
|
||||
* username of a user, group or channel, etc.).
|
||||
* @param {Number|String} chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
|
||||
* @return {Promise}
|
||||
* @see https://core.telegram.org/bots/api#getchat
|
||||
*/
|
||||
getChat(chatId) {
|
||||
const form = {
|
||||
chat_id: chatId
|
||||
};
|
||||
return this._request('getChat', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify an url to receive incoming updates via an outgoing webHook.
|
||||
* @param {String} url URL where Telegram will make HTTP Post. Leave empty to
|
||||
@ -757,8 +742,10 @@ class TelegramBot extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about the chat in form of a `Chat` object.
|
||||
* @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup
|
||||
* Use this method to get up to date information about the chat
|
||||
* (current name of the user for one-on-one conversations, current
|
||||
* username of a user, group or channel, etc.).
|
||||
* @param {Number|String} chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
|
||||
* @return {Promise}
|
||||
* @see https://core.telegram.org/bots/api#getchat
|
||||
*/
|
||||
@ -783,7 +770,7 @@ class TelegramBot extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of members in a chat in form of an `Int` object.
|
||||
* Use this method to get the number of members in a chat.
|
||||
* @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup
|
||||
* @return {Promise}
|
||||
* @see https://core.telegram.org/bots/api#getchatmemberscount
|
||||
@ -796,7 +783,7 @@ class TelegramBot extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about a member of a chat in form of a `ChatMember` object.
|
||||
* Use this method to get information about a member of a chat.
|
||||
* @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup
|
||||
* @param {String} userId Unique identifier of the target user
|
||||
* @return {Promise}
|
||||
|
@ -4,5 +4,7 @@ Running the tests:
|
||||
export TEST_TELEGRAM_TOKEN=<YOUR_BOT_TOKEN>
|
||||
# User Id which you want to send the messages.
|
||||
export TEST_USER_ID=<USER_ID>
|
||||
# Group Id which to use in some of the tests, e.g. for TelegramBot#getChat()
|
||||
export TEST_GROUP_ID=<GROUP_ID>
|
||||
npm run test
|
||||
```
|
||||
|
@ -14,6 +14,7 @@ if (!TOKEN) {
|
||||
|
||||
// Telegram service if not User Id
|
||||
const USERID = process.env.TEST_USER_ID || 777000;
|
||||
const GROUPID = process.env.TEST_GROUP_ID || -1001075450562;
|
||||
|
||||
describe('Telegram', function telegramSuite() {
|
||||
describe('#setWebHook', function setWebHookSuite() {
|
||||
@ -140,6 +141,34 @@ describe('Telegram', function telegramSuite() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getChatAdministrators', function getChatAdministratorsSuite() {
|
||||
it('should return an Array', function test() {
|
||||
const bot = new Telegram(TOKEN);
|
||||
return bot.getChatAdministrators(GROUPID).then(resp => {
|
||||
assert.ok(Array.isArray(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getChatMembersCount', function getChatMembersCountSuite() {
|
||||
it('should return an Integer', function test() {
|
||||
const bot = new Telegram(TOKEN);
|
||||
return bot.getChatMembersCount(GROUPID).then(resp => {
|
||||
assert.ok(Number.isInteger(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getChatMember', function getChatMemberSuite() {
|
||||
it('should return a ChatMember', function test() {
|
||||
const bot = new Telegram(TOKEN);
|
||||
return bot.getChatMember(GROUPID, USERID).then(resp => {
|
||||
assert.ok(is.object(resp.user));
|
||||
assert.ok(is.string(resp.status));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getUpdates', function getUpdatesSuite() {
|
||||
it('should return an Array', function test() {
|
||||
const bot = new Telegram(TOKEN);
|
||||
|
Loading…
x
Reference in New Issue
Block a user