Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integrations/telegram/integration.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import typingIndicator from './bp_modules/typing-indicator'

export default new IntegrationDefinition({
name: 'telegram',
version: '0.7.3',
version: '0.7.4',
title: 'Telegram',
description: 'Engage with your audience in real-time.',
icon: 'icon.svg',
Expand Down
24 changes: 13 additions & 11 deletions integrations/telegram/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ const integration = new bp.Integration({
ok(data.message, 'Handler received a non-message update, so the event was ignored')

const message = data.message as TelegramMessage
const conversationId = message.chat.id
const userId = message.from?.id
const telegramConversationId = message.chat.id
const telegramUserId = message.from?.id
const messageId = message.message_id

ok(!message.from?.is_bot, 'Handler received a message from a bot, so the message was ignored')
ok(conversationId, 'Handler received message with empty "chat.id" value')
ok(userId, 'Handler received message with empty "from.id" value')
ok(telegramConversationId, 'Handler received message with empty "chat.id" value')
ok(telegramUserId, 'Handler received message with empty "from.id" value')
ok(messageId, 'Handler received an empty message id')

const fromUser = message.from as User
Expand All @@ -183,26 +183,28 @@ const integration = new bp.Integration({
const { conversation } = await client.getOrCreateConversation({
channel: 'channel',
tags: {
id: conversationId.toString(),
fromUserId: userId.toString(),
id: telegramConversationId.toString(),
fromUserId: telegramUserId.toString(),
fromUserUsername: fromUser.username,
fromUserName: userName,
chatId: conversationId.toString(),
chatId: telegramConversationId.toString(),
},
discriminateByTags: ['id'],
})

const { user } = await client.getOrCreateUser({
tags: {
id: userId.toString(),
id: telegramUserId.toString(),
},
...(userName && { name: userName }),
discriminateByTags: ['id'],
})

const userFieldsToUpdate = {
pictureUrl: !user.pictureUrl
? await getUserPictureDataUri({
botToken: ctx.configuration.botToken,
telegramUserId: userId,
telegramUserId,
logger,
})
: undefined,
Expand All @@ -226,12 +228,12 @@ const integration = new bp.Integration({
telegram: telegraf.telegram,
})

logger.forBot().debug(`Received message from user ${userId}: ${JSON.stringify(message, null, 2)}`)
logger.forBot().debug(`Received message from user ${telegramUserId}: ${JSON.stringify(message, null, 2)}`)

await client.createMessage({
tags: {
id: messageId.toString(),
chatId: conversationId.toString(),
chatId: telegramConversationId.toString(),
},
...bpMessage,
userId: user.id,
Expand Down
Loading