Telegram
Create your first Telegram bot if you don't have one yet create your firts Telegram bot
Implementing a new communication channel such as telegram without affecting the logic of your project is very simple. Below you can find the starting point to implement the new telegram provider.
Install
pnpm install @builderbot-plugins/telegram
import { createBot, MemoryDB, createProvider, addKeyword, createFlow } from '@builderbot/bot'
import { TelegramProvider } from '@builderbot-plugins/telegram'
const welcomeFlow = addKeyword(['hi'])
.addAnswer('Ey! welcome')
.addAnswer('Your name is?', { capture: true }, async (ctx, { flowDynamic }) => {
await flowDynamic([`nice! ${ctx.body}`,'I will send you a funny image'])
})
.addAction(async(_ , {flowDynamic}) => {
const dataApi = await fetch(`https://shibe.online/api/shibes?count=1&urls=true&httpsUrls=true`)
const [imageUrl] = await dataApi.json()
await flowDynamic([{body:'😜', media: imageUrl}])
})
const main = async () => {
const adapterDB = new MemoryDB()
const adapterFlow = createFlow([welcomeFlow])
const adapterProvider = createProvider(TelegramProvider, {
token: 'YOUR_TELEGRAM_TOKEN_HERE'
})
await createBot({
flow: adapterFlow,
provider: adapterProvider,
database: adapterDB,
})
}
main()
In this way we have already implemented a new provider for Telegram keeping the same logic.