Skip to content

Commit 770ce54

Browse files
committed
fix send typing
1 parent 00b5972 commit 770ce54

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

packages/main/src/telegram_execution_context.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ export default class TelegramExecutionContext {
109109
}
110110
}
111111

112+
async sendTyping() {
113+
switch (this.update_type) {
114+
case 'message':
115+
return await this.api.sendChatAction(this.bot.api.toString(), {
116+
chat_id: this.update.message?.chat.id.toString() ?? '',
117+
action: 'typing',
118+
});
119+
case 'business_message':
120+
return await this.api.sendChatAction(this.bot.api.toString(), {
121+
business_connection_id: this.update.business_message?.business_connection_id.toString(),
122+
chat_id: this.update.business_message?.chat.id.toString() ?? '',
123+
action: 'typing',
124+
});
125+
default:
126+
break;
127+
}
128+
}
129+
112130
/**
113131
* Reply to the last message with text
114132
* @param message - text to reply with
@@ -118,10 +136,6 @@ export default class TelegramExecutionContext {
118136
async reply(message: string, parse_mode = '', options: Record<string, number | string | boolean> = {}) {
119137
switch (this.update_type) {
120138
case 'message':
121-
await this.api.sendChatAction(this.bot.api.toString(), {
122-
chat_id: this.update.message?.chat.id.toString() ?? '',
123-
action: 'typing',
124-
});
125139
return await this.api.sendMessage(this.bot.api.toString(), {
126140
...options,
127141
chat_id: this.update.message?.chat.id.toString() ?? '',
@@ -130,11 +144,6 @@ export default class TelegramExecutionContext {
130144
parse_mode,
131145
});
132146
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-
});
138147
return await this.api.sendMessage(this.bot.api.toString(), {
139148
chat_id: this.update.business_message?.chat.id.toString() ?? '',
140149
text: message,

packages/worker/src/worker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export default {
8181
.on('code', async (bot: TelegramExecutionContext) => {
8282
switch (bot.update_type) {
8383
case 'message': {
84+
await bot.sendTyping();
8485
const prompt = bot.update.message?.text?.toString().split(' ').slice(1).join(' ') ?? '';
8586
const messages = [{ role: 'user', content: prompt }];
8687
let response: AiTextGenerationOutput;
@@ -211,6 +212,7 @@ export default {
211212
.on(':message', async (bot: TelegramExecutionContext) => {
212213
switch (bot.update_type) {
213214
case 'message': {
215+
await bot.sendTyping();
214216
const prompt = bot.update.message?.text?.toString() ?? '';
215217
const { results } = await env.DB.prepare('SELECT * FROM Messages WHERE userId=?')
216218
.bind(bot.update.inline_query ? bot.update.inline_query.from.id : bot.update.message?.from.id)
@@ -270,6 +272,7 @@ export default {
270272
break;
271273
}
272274
case 'business_message': {
275+
await bot.sendTyping();
273276
const prompt = bot.update.business_message?.text?.toString() ?? '';
274277
const { results } = await env.DB.prepare('SELECT * FROM Messages WHERE userId=?')
275278
.bind(

0 commit comments

Comments
 (0)