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/email/integration.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const emailSchema = z.object({

export default new IntegrationDefinition({
name: 'email',
version: '0.0.1',
version: '0.1.0',
readme: 'hub.md',
icon: 'icon.svg',
configuration: {
Expand Down
2 changes: 2 additions & 0 deletions integrations/email/src/imap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export const getMessages = async function (
imapBodies.push('TEXT')
}

if (box.messages.total === 0) return { messages: [] }

const { firstElementIndex, lastElementIndex } = paging.pageToSpan({
page: range.page,
perPage: range.perPage,
Expand Down
5 changes: 4 additions & 1 deletion integrations/email/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export const register: bp.IntegrationProps['register'] = async (props) => {
await getMessages({ page: 0, perPage: 1 }, props)
} catch (thrown: unknown) {
const err = thrown instanceof Error ? thrown : new Error(`${thrown}`)
throw new sdk.RuntimeError('An error occured when registering the integration. Verify your configuration.', err)
console.log(err.message)
throw new sdk.RuntimeError(
`An error occured when registering the integration: ${err.message} Verify your configuration.`
)
}
}

Expand Down
48 changes: 48 additions & 0 deletions integrations/telegram/definitions/channels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { z, messages } from '@botpress/sdk'

const _textMessageDefinition = {
...messages.defaults.text,
schema: messages.defaults.text.schema.extend({
text: messages.defaults.text.schema.shape.text
.max(4096)
.describe('The text content of the Telegram message (Limit 4096 characters)'),
}),
}

const _imageMessageDefinition = {
...messages.defaults.image,
schema: messages.defaults.image.schema.extend({
caption: z.string().optional().describe('The caption/description of the image'),
}),
}

const _audioMessageDefinition = {
...messages.defaults.audio,
schema: messages.defaults.audio.schema.extend({
caption: z.string().optional().describe('The caption/transcription of the audio message'),
}),
}

const _blocSchema = z.union([
z.object({ type: z.literal('text'), payload: _textMessageDefinition.schema }),
z.object({ type: z.literal('image'), payload: _imageMessageDefinition.schema }),
z.object({ type: z.literal('audio'), payload: _audioMessageDefinition.schema }),
z.object({ type: z.literal('video'), payload: messages.defaults.video.schema }),
z.object({ type: z.literal('file'), payload: messages.defaults.file.schema }),
z.object({ type: z.literal('location'), payload: messages.defaults.location.schema }),
])

const _blocMessageDefinition = {
...messages.defaults.bloc,
schema: z.object({
items: z.array(_blocSchema),
}),
}

export const telegramMessageChannels = {
...messages.defaults,
text: _textMessageDefinition,
image: _imageMessageDefinition,
audio: _audioMessageDefinition,
bloc: _blocMessageDefinition,
}
15 changes: 15 additions & 0 deletions integrations/telegram/hub.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
<iframe src="https://www.youtube.com/embed/w0-UGm4mu74"></iframe>

The Telegram integration allows your AI-powered chatbot to seamlessly interact with Telegram, a popular messaging platform with a large user base. Connect your chatbot to Telegram and engage with your audience in real-time conversations. With this integration, you can automate customer support, provide personalized recommendations, send notifications, and handle inquiries directly within Telegram. Leverage Telegram's rich features, including text messages, inline buttons, media files, and more, to create dynamic and interactive chatbot experiences. Empower your chatbot to deliver exceptional user experiences on Telegram with the Telegram Integration for Botpress.

## Migrating from version `0.x.x` to `1.x.x`

### Removal of proactive conversations (and proactive users)

- Telegram does not currently support proactive conversations, so any bots using this feature will need to be updated to use the normal conversation flow.

### Removal of dedicated Markdown messages type

- The `markdown` channel message type is being deprecated in favor of integrating this behavior into the base `text` message type.
- This new Markdown behavior (commonmark spec) will allow image Markdown. However, since Telegram does not support mixed message types, it will split the message into multiple messages with images sent in between text messages.

### Addition of message limits

- Telegram has a message length limit of 4096 characters, so that limit has been added to the text parameter in the `text` message payload. Going over this limit will result in the message being rejected.
18 changes: 4 additions & 14 deletions integrations/telegram/integration.definition.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* bplint-disable */
import { z, IntegrationDefinition, messages } from '@botpress/sdk'
import { z, IntegrationDefinition } from '@botpress/sdk'
import { sentry as sentryHelpers } from '@botpress/sdk-addons'
import typingIndicator from './bp_modules/typing-indicator'
import { telegramMessageChannels } from './definitions/channels'

export default new IntegrationDefinition({
name: 'telegram',
version: '0.7.4',
version: '1.0.0',
title: 'Telegram',
description: 'Engage with your audience in real-time.',
icon: 'icon.svg',
Expand All @@ -17,20 +18,10 @@ export default new IntegrationDefinition({
},
channels: {
channel: {
messages: {
...messages.defaults,
markdown: messages.markdown,
audio: {
...messages.defaults.audio,
schema: messages.defaults.audio.schema.extend({
caption: z.string().optional().describe('The caption/transcription of the audio message'),
}),
},
},
messages: telegramMessageChannels,
message: { tags: { id: {}, chatId: {} } },
conversation: {
tags: { id: {}, fromUserId: {}, fromUserUsername: {}, fromUserName: {}, chatId: {} },
creation: { enabled: true, requiredTags: ['id'] },
},
},
},
Expand All @@ -41,7 +32,6 @@ export default new IntegrationDefinition({
tags: {
id: {},
},
creation: { enabled: true, requiredTags: ['id'] },
},
}).extend(typingIndicator, () => ({
entities: {},
Expand Down
7 changes: 6 additions & 1 deletion integrations/telegram/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@
"@botpress/sdk": "workspace:*",
"@botpress/sdk-addons": "workspace:*",
"lodash": "^4.17.21",
"markdown-it": "^14.1.0",
"nanoid": "^5.1.5",
"sanitize-html": "^2.17.0",
"telegraf": "^4.16.3"
},
"devDependencies": {
"@botpress/cli": "workspace:*",
"@botpress/common": "workspace:*",
"@botpresshub/typing-indicator": "workspace:*",
"@sentry/cli": "^2.39.1",
"@types/lodash": "^4.14.191"
"@types/lodash": "^4.14.191",
"@types/markdown-it": "^14.1.2",
"@types/sanitize-html": "^2.16.0"
},
"bpDependencies": {
"typing-indicator": "../../interfaces/typing-indicator"
Expand Down
Loading
Loading