npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@botonic/example-telco-offers

v0.30.0

Published

This example shows you a multi-language conversation flow to acquire an Internet or a cell phone rate using buttons and replies.

Downloads

13

Readme

Botonic Telco

This example shows you a multi-language conversation flow to acquire an Internet or a cell phone rate using buttons and replies.

What's in this document?

How to use this example

  1. From your command line, download the example by running:
    $ botonic new <botName> telco-offers
  2. cd into <botName> directory that has been created.
  3. Run botonic serve to test it in your local machine.

Routes and Actions

Routes map user inputs to actions which consist of simple units of logic that your bot can perform and the response that your bot generates.

Here we can see a few examples of how we have captured the user input.

src/routes.js

import Start from './actions/start'
import ChooseLanguage from './actions/choose_language'
import Phone from './actions/phone'
import BuyPhone from './actions/buy-phone'
import Bye from './actions/bye'

export const routes = [
  { path: 'hi', payload: 'hi', action: ChooseLanguage },
  { path: 'set-language', payload: /language-.*/, action: Start },
  {
    path: 'phone',
    payload: 'phone',
    action: Phone,
    childRoutes: [
      {
        path: 'buyPhone',
        payload: /buyPhone-.*/,
        action: BuyPhone,
      },
    ],
  },
  { path: 'bye', text: /.*/, payload: /bye-.*/, action: Bye },
]

If a rule matches it will trigger an action:

src/actions/choose-language.jsx

import React from 'react'
import { Text, Reply } from '@botonic/react'

export default class extends React.Component {
  render() {
    return (
      <>
        <Text>Hi! Before we start choose a language: {'\n'}</Text>
        <Text>
          Hola! Antes de empezar elige un idioma:
          <Reply payload='language-es'>Español</Reply>
          <Reply payload='language-en'>English</Reply>
        </Text>
      </>
    )
  }
}

Locales

The Locales allows us to build a bot that supports different languages. To do so, we have separated our string literals from the code components. In the src/locales folder we have added a js file for each language we want to support.

src/locales/en.js

export default {
  internet: ['Internet'],
  phone: ['Cell Phone'],
  tv: ['TV'],
  extra_phone: ['Extra Cell Phone'],
  speed: ['Speed'],
  price: ['Price'],

  start_text: [
    'Welcome, I am your virtual assistant of Botonic Telco, select which service you want to hire?',
  ],
  ask_more: ['Do you want to hire any more rate?'],
}

src/locales/es.js

export default {
  internet: ['Fibra'],
  phone: ['Móvil'],
  tv: ['TV'],
  extra_phone: ['Extra móvil'],
  speed: ['Velocidad'],
  price: ['Precio'],

  start_text: [
    'Bienvenido soy tu asistente virtual de Botonic Telco, selecciona que servicio quieres contratar?',
  ],
  ask_more: ['Quieres contratar alguna tarifa más?'],
}

Then, we have exported these languages.

src/locales/index.js

import en from './en'
import es from './es'

export const locales = { en, es }

In the initial action we have set the locale and then we can access an object from locales with this.context.getString method.

src/actions/start.jsx

import React from 'react'
import { RequestContext, Text, Button } from '@botonic/react'

export default class extends React.Component {
  static contextType = RequestContext
  static async botonicInit(request) {
    const language = request.input.payload.split('-')[1]
    return { language }
  }
  render() {
    this.props.language && this.context.setLocale(this.props.language)
    let _ = this.context.getString
    return (
      <>
        <Text>
          {_('start_text')}
          <Button payload='internet'>{_('internet')}</Button>
          <Button payload='phone'>{_('phone')}</Button>
        </Text>
      </>
    )
  }
}

Webchat Settings

The Webchat Settings component can be appended at the end of a message to change Webchat properties dynamically.

We have used it to enable the user input in one of the last actions.

src/actions/confirm.jsx

import React from 'react'
import { RequestContext, Text, WebchatSettings } from '@botonic/react'

export default class extends React.Component {
  static contextType = RequestContext

  render() {
    let _ = this.context.getString
    return (
      <>
        <Text> {_('confirm.text')}</Text>
        <WebchatSettings
          theme={{
            userInput: {
              box: {
                style: {
                  background: '#F5F5F5',
                },
              },
            },
          }}
          enableUserInput={true}
        />
      </>
    )
  }
}

...and we are done 🎉