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

@bottender/proposal-conversation

v0.1.0

Published

A candidate of the Bottender conversation module

Downloads

2

Readme

bottender-proposal-conversation

A candidate of the Bottender conversation module

Installation

npm install @bottender/proposal-conversation

Or

yarn add @bottender/proposal-conversation

Usage

First of all, you have to wrap your root App entry in the run function exported by this package:

const { run } = require('@bottender/proposal-conversation');

module.exports = run(function App() {
  // ...
});

Because we implemented this proposal outside of the bottender package, calling the run function is necessary here to extend the default behavior of the Bottender framework.

After that you may use the registerAction function to register actions which can return a prompt call as the return value. By doing so, when the user answers the question, this action is executed again and the input text becomes the props of the action:

const { run, registerAction, getAction, prompt } = require('@bottender/proposal-conversation');

registerAction('AskLikeCheeseOrNot', async function AskLikeCheeseOrNot(
  context,
  props
) {
  if (!props.result) {
    await context.sendText('Do you like cheese? (yes/no)');
    return prompt('result');
  }

  if (props.result === 'yes') {
    await context.sendText('You said yes! How wonderful.');
  } else if (props.result === 'no') {
    await context.sendText('You said no, that is too bad.');
  } else {
    await context.sendText('Sorry I did not understand.');
  }
});

module.exports = run(function App() {
  return getAction('AskLikeCheeseOrNot');
});

Examples

We have a bunch of examples in the examples folder.

API

registerAction(name: string, action: Action)

Register the action.

const { registerAction } = require('@bottender/proposal-conversation');

registerAction('AskLikeCheeseOrNot', async function AskLikeCheeseOrNot(
  context,
  props
) {
  // ...
});

Note: You must call registerAction before calling the getAction function, so we recommend putting them on the top of the index.js or src/index.js file.

getAction(name: string)

Get the registered action by the name.

const { getAction } = require('@bottender/proposal-conversation');

const action = getAction('AskLikeCheeseOrNot');

prompt(key: string)

const { prompt } = require('@bottender/proposal-conversation');

Note: prompt can only be used inside the registered action.

setField(context: Context, field: string, value: any)

Set the value of the field.

const { setField } = require('@bottender/proposal-conversation');

registerAction('AskName', async function AskName(context, props) {
  if (!props.name) {
    await context.sendText('Please type your name:');
    return prompt('name');
  }

  let name = props.name;
  if (props.name.length > 30) {
    name = `${props.name.slice(0, 27)}...`;
    setField(context, 'name', name);
    await context.sendText(
      `Name can't be more than 30 characters. Set your name to ${name}`
    );
  }

  // ...
});

Note: setField can only be used inside the registered action.

deleteField(context: Context, field: string | string[])

Delete the value of the field.

const { deleteField } = require('@bottender/proposal-conversation');

registerAction('AskNameAndPhone', async function AskNameAndPhone(context, props) {
  if (!props.name) {
    await context.sendText('Please type your name:');
    return prompt('name');
  }

  if (!props.phone) {
    await context.sendText('Please type your phone number:');
    return prompt('phone');
  }

  if (!props.confirm) {
    await context.sendText(
      `${props.name}, your phone number is ${props.phone}, right? If not, which part you want to refill? (yes|name|phone)`
    );
    return prompt('confirm');
  }

  if (props.confirm === 'yes') {
    await context.sendText(
      `Thank you for your help, your personal data was stored correctly.`
    );
  } else if (props.confirm === 'name') {
    deleteField(context, ['name', 'confirm']);
    await context.sendText('Please retype your name:');
    return prompt('name');
  } else if (props.confirm === 'phone') {
    deleteField(context, ['phone', 'confirm']);
    await context.sendText('Please retype your phone again:');
    return prompt('phone');
  } 
});

Note: deleteField can only be used inside the registered action.

run(action: Action)

The extension of the runner in the Bottender framework.

module.exports = run(function App() {
  // ...
});