Plugins · Telegram
Edit this page on GitHubTelegram
Create your first Telegram bot if you don't have one yet create your first 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/telegramimport { 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.
Resources
Modularize
Learn how to modularise flows so that you can have a more maintainable bot.
Send Message
How to send a message via HTTP to start conversations, you can send multimedia as well.
Dockerizer
A good practice is to dockerise your bots to make them more maintainable and effective.
Events
Learning about events will make us more fluent when creating chatbots.