🚀 ¡Nuevo! builderbot cloud para No-code ¡Pruébalo gratis!

Twilio Uses Cases

import { createBot, createProvider, createFlow, addKeyword } from '@builderbot/bot'
import { MemoryDB as Database } from '@builderbot/bot'
import { TwilioProvider as Provider } from '@builderbot/provider-twilio'

const PORT = process.env.PORT ?? 3008

const welcomeFlow = addKeyword<Provider, Database>(['test'])
    .addAnswer('send files...')
    .addAnswer(`Send image from URL`,
        { media: 'https://builderbot.vercel.app/_next/static/media/logo-v2.5d15651a.png' }
    )
    .addAnswer(`Send video from URL`,
        { media: 'https://media.giphy.com/media/KWZKwdBC2ODWlQ8kgt/giphy.mp4' }
    )
    .addAnswer(`Send audio from URL`,
        { media: 'https://cdn.freesound.org/previews/728/728142_11861866-lq.mp3' }
    )
    .addAnswer(`Send file from URL`,
        { media: 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf' }
    )
    .addAnswer(`First Way to Send Buttons`, {
        buttons:
            [
                { body: 'Order' },
                { body: 'Register' },
                { body: 'Catalog' }
            ]
    })

const main = async () => {
    const adapterFlow = createFlow([welcomeFlow])
    const adapterProvider = createProvider(Provider, {
        accountSid: process.env.ACCOUNT_SID,
        authToken: process.env.AUTH_TOKEN,
        vendorNumber: process.env.VENDOR_NUMBER,
    })
    const adapterDB = new Database()

    const { handleCtx, httpServer } = await createBot<Provider>({
        flow: adapterFlow,
        provider: adapterProvider,
        database: adapterDB,
    })

    adapterProvider.server.post(
        '/v1/samples',
        handleCtx(async (bot, req, res) => {
            try {
                const { number, message, urlMedia } = req.body

                await bot.sendMessage(number, message, { media: urlMedia ?? null })

                await bot.provider.sendMessage(number, message, {})

                return res.end('ok')

            } catch (error) {
                console.log(error)
                return res.end('error')
            }
        })
    )

    httpServer(+PORT)

}

main()


Guides

My first chatbot

Learn how build your first chatbot in few minutes

Read more

Concepts

Understand the essential concepts for building bots

Read more

Add Functions

The key to learning how to write flows is add-functions.

Read more

Plugins

Unlimitate and start implementing the community plugins.

Read more

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.