Skip to content

Commit f87af40

Browse files
committed
business messages work now
1 parent 6f61c97 commit f87af40

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

packages/main/src/telegram_api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ export default class TelegramApi {
4747
async sendMessage(
4848
botApi: string,
4949
data: {
50-
reply_to_message_id: number | string;
50+
reply_to_message_id?: number | string;
5151
chat_id: number | string;
5252
text: string;
5353
parse_mode: string;
54+
business_connection_id?: number | string;
5455
},
5556
) {
5657
const url = this.getApiUrl(botApi, 'sendMessage', data);
58+
console.log(url.url);
5759
return await fetch(url);
5860
}
5961

@@ -111,7 +113,6 @@ export default class TelegramApi {
111113
return await fetch(url);
112114
}
113115

114-
115116
/**
116117
* Send an callback response to a given botApi
117118
* @param botApi - full URL to the telegram API without slug

packages/main/src/telegram_execution_context.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export default class TelegramExecutionContext {
3535
this.update_type = 'document';
3636
} else if (this.update.callback_query?.id) {
3737
this.update_type = 'callback';
38+
} else if (this.update.business_message?.text) {
39+
this.update_type = 'business_message';
3840
}
3941
}
4042

@@ -125,10 +127,9 @@ export default class TelegramExecutionContext {
125127
});
126128
case 'business_message':
127129
return await this.api.sendMessage(this.bot.api.toString(), {
128-
...options,
129130
chat_id: this.update.business_message?.chat.id.toString() ?? '',
130-
reply_to_message_id: this.update.business_message?.message_id.toString() ?? '',
131131
text: message,
132+
business_connection_id: this.update.business_message?.business_connection_id.toString(),
132133
parse_mode,
133134
});
134135
case 'photo':

packages/worker/src/worker.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,13 @@ export default {
268268
case 'business_message': {
269269
const prompt = bot.update.business_message?.text?.toString() ?? '';
270270
const { results } = await env.DB.prepare('SELECT * FROM Messages WHERE userId=?')
271-
.bind(bot.update.inline_query ? bot.update.inline_query.from.id : bot.update.message?.from.id)
271+
.bind(
272+
bot.update.inline_query
273+
? bot.update.inline_query.from.id
274+
: bot.update.business_message
275+
? bot.update.business_message.from.id
276+
: bot.update.message?.from.id,
277+
)
272278
.all();
273279
const message_history = results.map((col) => ({ role: 'system', content: col.content as string }));
274280
const messages = [
@@ -294,7 +300,11 @@ export default {
294300
await env.DB.prepare('INSERT INTO Messages (id, userId, content) VALUES (?, ?, ?)')
295301
.bind(
296302
crypto.randomUUID(),
297-
bot.update.inline_query ? bot.update.inline_query.from.id : bot.update.message?.from.id,
303+
bot.update.inline_query
304+
? bot.update.inline_query.from.id
305+
: bot.update.business_message
306+
? bot.update.business_message.from.id
307+
: bot.update.message?.from.id,
298308
`'[INST] ${prompt} [/INST] \n ${response.response}`,
299309
)
300310
.run();

0 commit comments

Comments
 (0)