2.0.0 • Published 6 years ago

starbot-story-bot v2.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

starbot-story-bot NPM version Build Status

About

Story bot for StarBot

Installation

$ npm install --save starbot-story-bot

Using

const StoryBot = require('starbot-story-bot');
const story = require('./story');

const bot = StoryBot({
  story,
  modules: {
    damage: ({ action, message, state }) => state
  },
  unrecognizedText: 'I don`t understand',
});

story.json

  {
    "0": {
      "text": "Hello. What is your name?",
      "actions": [
        {
          "name": "goto",
          "position": "1"
        },
        {
          "name": "set",
          "key": "name"
        }
      ]
    },
    "1": {
      "text": "Nice to meet you, {{name}}. Choose option 1 or 2?",
      "actions": [
        {
          "name": "goto",
          "map": {
            "1": "2",
            "2": "3"
          }
        }
      ]
    },
    "2": {
      "text": "You chose the first option. Great. Now I'm going to bring you to a random location",
      "actions": [
        {
          "name": "goto",
          "random": ["1", "4", "5"]
        }
      ]
    },
    "3": {
      "text": "You chose the second option. Well. Well",
      "actions": [
        {
          "name": "goto",
          "position": "0"
        }
      ]
    },
    "4": {
      "text": "Congratulations, you're in 4th place",
      "actions": [
        {
          "name": "goto",
          "position": "0"
        }
      ]
    },
    "5": {
      "text": "Congratulations, you're in 5th place",
      "actions": [
        {
          "name": "goto",
          "position": "0"
        }
      ]
    }
  },

Story

{
   // 1th Scene
  "id1Scene": {},
   // 2nd Scene
  "id2Scene": {}
  ...
}

Scene

{
  // The message is processed by the mustache template engine in the context of the user state
  "text": "Message for user",
  // Array of actions (instructions for processing input)
  "actions": [{}, {}]
}

Action

{
  // Name of the action. Built-in: 'goto' and 'set'
  "name": "goto",
  ...
}

Build-in action

goto

Change user position to position. The position of the user corresponds to the ID of the scene.

{
  "name": "goto",
  "position": "room7",
  "notFoundText": "Sorry, not found.."
}

set

Sets the value field key user state

{
  "name": "set",
  "key": "someField",
  "value": "some value",
  "notFoundText": "Sorry, not found.."
}

Custom action

Blank module:

/**
 * @param {any} state Current state of the user
 * @param {Number|String} value Value from "value", "random" or "map" field of action
 * @param {String} message The message that the user entered 
 * @param {Object} action Action object
 *
 * @returns {any} New state of the user
 */
module.exports = function ({ action, message, state }) {
  return state;
};

License

MIT © antitim

2.0.0

6 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago