diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index f7c752a..df173f6 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -22,11 +22,11 @@ jobs:
with:
telegram-api-token: ${{ secrets.TELEGRAM_API_TOKEN }}
telegram-chat-id: ${{ secrets.TELEGRAM_CHAT_ID }}
- question: 'Updating Telenode. Which bump type you wish to perform?'
+ question: 'Updating Telenode. Which bump type you wish to perform? Default is "skip"'
options: '["prerelease", "patch", "minor", "major", "skip"]'
default-choice: 'skip'
message: 'The selected bump type is: %s'
- timeout: 45
+ timeout: 30
wait-for-timeout-to-finish: true
bump:
@@ -78,11 +78,11 @@ jobs:
with:
telegram-api-token: ${{ secrets.TELEGRAM_API_TOKEN }}
telegram-chat-id: ${{ secrets.TELEGRAM_CHAT_ID }}
- question: 'Should publish to npm?'
+ question: 'Should publish to npm? Default is "no"'
options: '["yes", "no"]'
default-choice: 'no'
message: 'The selected choice is: %s'
- timeout: 45
+ timeout: 30
wait-for-timeout-to-finish: true
publish:
diff --git a/README.md b/README.md
index 086c122..201562b 100644
--- a/README.md
+++ b/README.md
@@ -25,9 +25,13 @@ Lightweight Telegram API framework for Node.js
✅ Secret token support
✅ Long polling support
+
+✅ Sending chat action
## Getting started
+#### Complete example can be found [here](https://github.com/NivEz/movie-info-bot)
+
### Installation
```shellscript
diff --git a/examples/chatAction.js b/examples/chatAction.js
new file mode 100644
index 0000000..e5dd4f0
--- /dev/null
+++ b/examples/chatAction.js
@@ -0,0 +1,23 @@
+const Telenode = require('../src/bot');
+
+const bot = new Telenode({
+ apiToken: process.env.API_TOKEN,
+});
+
+bot.createServer();
+
+bot.onTextMessage('', async messageBody => {
+ await bot.sendTextMessage(
+ 'I will be taking a random action for five seconds',
+ messageBody.chat.id,
+ );
+ const randomIdx = Math.floor(Math.random() * bot.validChatActions.length);
+ await bot.sendChatAction(messageBody.chat.id, bot.validChatActions[randomIdx]);
+ await sleep(5000);
+ await bot.sendTextMessage(
+ 'The following API call will end the chat action',
+ messageBody.chat.id,
+ );
+});
+
+const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
diff --git a/src/bot.js b/src/bot.js
index 9d9fddf..96c66a3 100644
--- a/src/bot.js
+++ b/src/bot.js
@@ -5,6 +5,19 @@ const axios = require('axios');
class Telenode {
#baseUrl;
#secretToken;
+ validChatActions = [
+ 'typing',
+ 'upload_photo',
+ 'record_video',
+ 'upload_video',
+ 'record_voice',
+ 'upload_voice',
+ 'upload_document',
+ 'choose_sticker',
+ 'find_location',
+ 'record_video_note',
+ 'upload_video_note',
+ ];
constructor({ apiToken, secretToken }) {
this.textHandlers = {};
@@ -186,6 +199,21 @@ class Telenode {
},
});
}
+
+ async sendChatAction(chatId, chatAction) {
+ if (!this.validChatActions.includes(chatAction)) {
+ throw new Error(
+ `Invalid chat action. Valid chat action should be one of: ${this.validChatActions.join(
+ ', ',
+ )}`,
+ );
+ }
+ const url = this.#baseUrl + '/sendChatAction';
+ await axios.post(url, {
+ chat_id: chatId,
+ action: chatAction,
+ });
+ }
}
module.exports = Telenode;