Skip to content

Commit 00b5972

Browse files
committed
send typing
1 parent 5980b0e commit 00b5972

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/main/src/telegram_api.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export default class TelegramApi {
1919
return new Request(`${request.toString()}?${params.toString()}`);
2020
}
2121

22+
async sendChatAction(botApi: string, data: { business_connection_id?: string; chat_id: number | string; action: string }) {
23+
const url = this.getApiUrl(botApi, 'sendChatAction', data);
24+
const response = await fetch(url);
25+
return response;
26+
}
27+
2228
/**
2329
* Get a file with a given file_id
2430
* @param botApi - full URL to the telegram API without slug

packages/main/src/telegram_execution_context.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ export default class TelegramExecutionContext {
118118
async reply(message: string, parse_mode = '', options: Record<string, number | string | boolean> = {}) {
119119
switch (this.update_type) {
120120
case 'message':
121+
await this.api.sendChatAction(this.bot.api.toString(), {
122+
chat_id: this.update.message?.chat.id.toString() ?? '',
123+
action: 'typing',
124+
});
121125
return await this.api.sendMessage(this.bot.api.toString(), {
122126
...options,
123127
chat_id: this.update.message?.chat.id.toString() ?? '',
@@ -126,6 +130,11 @@ export default class TelegramExecutionContext {
126130
parse_mode,
127131
});
128132
case 'business_message':
133+
await this.api.sendChatAction(this.bot.api.toString(), {
134+
business_connection_id: this.update.business_message?.business_connection_id.toString(),
135+
chat_id: this.update.business_message?.chat.id.toString() ?? '',
136+
action: 'typing',
137+
});
129138
return await this.api.sendMessage(this.bot.api.toString(), {
130139
chat_id: this.update.business_message?.chat.id.toString() ?? '',
131140
text: message,

0 commit comments

Comments
 (0)