Giter VIP home page Giter VIP logo

smooch-bot's Introduction

Smooch BotBuild Status

http://blog.smooch.io/how-to-build-your-own-smooch-bot/

A simple generic chat bot with persisted conversation state and user properties. You can also run your bot on top of smooch.io.

This framework is designed with the intent of giving you full control over how you want your bot to behave, and extensibliity allowing you to easily connect it to a variety of APIs and communication channels (Smooch or otherwise). This comes at the cost of features. Unlike many popular bot tools and services that are available today, smooch-bot assumes very little and therefore offers a reduced set of tools for you to use to build common bot scenarios. This framework gives you an asynchronous conversation state and user property persistence model to build off of, but the rest is up to you.

This framework is also not to be confused with https://github.com/gozman/smoochbot, which is a Smooch connector for BotKit (howdyai/botkit).

A bot consists of three core components:

  1. Bot: The heart of your bot. Your Bot implements a say() method. The bot also needs to be provided with a store implementation for saving conversation state and user properties, as well as a lock implementation for synchronizing tasks.

  2. Script: The chat script. This defines what your bot will say and how it should respond to user input.

  3. StateMachine: This is the engine that uses the Bot to guide a session from one Script step to the next.

SmoochApiBot and SmoochApiStore allow you to run your chat bot on top of smooch.io. That means you can run your bot over SMS, Web, iOS, Android, you name it! You can also hook your conversations up to back end channels such as Slack and HipChat so that a human jump in the conversation whenever you like.

To see this bot in action, check out the examples here: https://github.com/smooch/smooch-bot-example

smooch-bot's People

Contributors

alavers avatar julianfox avatar narisso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smooch-bot's Issues

Single smoochApp hosted on multiple heroku instances

Hello.

Here is scenario I am facing. I have hosted two separate heroku instances with the single smooch app (i.e using same SMOOCH_APP_TOKEN, SMOOCH_KEY_ID and SMOOCH_SECRET for my both apps)

Note: Its our business need to use the single smooch app deployed on multiple heroku instances

image

Now when both server starts running, both create a new webhook (i.e named /webhook) on my smooch app dashboard with two different targets as shown in following image

image

Now what happens when I send any message to my Bot from any appUser (i.e web) the bot reply received/appears twice on appUser screen. like as shown in image below.

image

Question:
How to control this? I want my bot should send response once.

How to use bot.setProp("silent", true)

Hi there.

Is there any feature in this bot i.e To turn bot (auto response/reply) off and let our real Human Agent to answer the customer queries.

I have done this bot.setProp("silent", true) but its not working.

Basically I expected that setting the silent property to true will ignore all the methods i.e bot.say("bla bla bla"); Does this works like that?

How to move Bot to a session from one Script step to the next.

From Docs
StateMachine: This is the engine that uses the Bot to guide a session from one Script step to the next.

I have two scenarios.

  1. Simply I have to move Bot from one Script step to the next step's PROMPT function.
  2. I have to move Bot from one Script step to the next step's RECEIVE function with some params passed in

to handle this I have done like below.

function handleChangeStateMachine(stateMachine, res, ai_action, params){

    console.log("Change state to => "+ ai_action + " Prompt " + params.should_prompt);

    if(params.should_prompt == "true"){

        console.log("IF Prompt " + params.should_prompt);
        // Scenario 1
        Promise.all([
            stateMachine.bot.releaseLock(),
            stateMachine.setState(ai_action),   // set new state
            stateMachine.prompt(ai_action)      // goto prompt
        ]);
        res.end();

    }else{

        console.log("ELSE Prompt " + params.should_prompt);
        // Scenario 2
        Promise.all([
            stateMachine.bot.releaseLock(),
            stateMachine.setState(ai_action),   // set new state
            stateMachine.receiveMessage(params) // goto receiveMessage
        ]);
        res.end(); 
    }
}

QUESTION(s):

  1. Is this correct way? Please mention other method if any.

PROBLEM(s):

  1. I am facing issue sometimes in my 2nd scenario (sometimes it works perfectly)
    problem is that my bot is not moving to next step's receiveMessage() function but it remains in the previous state and my params passed in previous state. Hence my bot doesn't respond correctly.

bot.SetProp() inconsistently works

Whenever I use bot.setProp in my Script, it inconsistently saves the properties I use. It is necessary to retain certain values in the Smooch Store for my bot, but it is also essential that I clear them out after I use them. When I try to clear them with bot.setProp('property', ""), it only clears out certain properties while other retain their value. This persistence of properties is holding my bot from production.

how to move bot receive step in script.js

How to send bot another state's receive step in script.js file.

I can do this in heroku/index.js page using the following code.

for going receive I have to do it like

 Promise.all([
            stateMachine.bot.releaseLock(),
            stateMachine.setState(ai_action),   // set new state
            stateMachine.receive(ai_action)      // goto receive
        ]);

I need to do this same in script.js

Bot states inconsistent with multiple user messages.

My team and I have written a custom state in the Script for the smooch bot. It works exactly as expected when we feed it messages (as a user) one at time. However, sometimes when we send multiple messages one after the other (as a real user might) the bot behaves unpredictably. Sometimes it doesn't finish executing everything written in the state. Sometimes it just restarts the state.

This happens even for our simple start state where the bot waits for the user to say something and responds 'Hello' and moves onto the next, different state. If the user says 'hi' four times in four separate lines quickly, the bot responds by saying 'Hello' four times (sometimes even giving the processing 'beep boop' message) instead of just say 'Hello' once and treating the next user message line as input for the next state.

This seems like a significant issues. Is there anyway to ensure that a state executes to its entirety before it attempts to read in another user message?

Clearing State

Hello,

Is there a quick way to clear the stateMachine at all?

For testing the bot, I would like to clear all state on previous conversations/loads so that I can start from the beginning of the script each time without having to clear cache etc.

Thanks,

Send image to users from smooch-bot

I have gone through the source code of smooch-bot.
there is a method bot.say()

i.e https://github.com/smooch/smooch-bot/blob/master/lib/bot.js#L15
say(text) { return new Promise((resolve) => { // Do nothing resolve(); }); }

and is responsible to send the text message to user. Right?

I want to send the image to users from smooch-bot
is there anything like that in this smooch-bot?

something like

sendImage(image) { return new Promise((resolve) => { // Do nothing resolve(); }); }

getting Error: Conflict while switching from one step to next

I am trying to move my bot from one step to next. but I am getting error. log is shown below.

Here is my code to switch step from one to other.

stateMachine.setState(ai_action)
        .catch((err) => {
            console.error('SmoochBot error: setState', err);  // Here its crashing. and getting the Error Conflict with status code 409, log is given below
            res.end();
        });

        stateMachine.receiveMessage(params)
        .then(() => res.end())
        .catch((err) => {
            console.error('SmoochBot error: receiveMessage', err);
            res.end();
        });

Error log

_Jul 20 23:08:50 qjamesbot-staging app/web.1: SmoochBot error: setState { Error: Conflict
Jul 20 23:08:50 qjamesbot-staging app/web.1: at handleStatus (/app/node_modules/smooch-bot/node_modules/smooch-core/lib/utils/http.js:45:17)
Jul 20 23:08:50 qjamesbot-staging app/web.1: at process._tickCallback (internal/process/next_tick.js:109:7)
Jul 20 23:08:50 qjamesbot-staging app/web.1: response:
Jul 20 23:08:50 qjamesbot-staging app/web.1: Body {
Jul 20 23:08:50 qjamesbot-staging app/web.1: url: 'https://api.smooch.io/v1/appusers/2b08d6523c53317795409268',
Jul 20 23:08:50 qjamesbot-staging app/web.1: status: 409,
Jul 20 23:08:50 qjamesbot-staging app/web.1: statusText: 'Conflict',
Jul 20 23:08:50 qjamesbot-staging app/web.1: headers: Headers { _headers: [Object] },
Jul 20 23:08:50 qjamesbot-staging app/web.1: ok: false,
Jul 20 23:08:50 qjamesbot-staging app/web.1: body:
Jul 20 23:08:50 qjamesbot-staging app/web.1: PassThrough {
Jul 20 23:08:50 qjamesbot-staging app/web.1: _readableState: [Object],
Jul 20 23:08:50 qjamesbot-staging app/web.1: readable: true,
Jul 20 23:08:50 qjamesbot-staging app/web.1: domain: null,
Jul 20 23:08:50 qjamesbot-staging app/web.1: _events: [Object],
Jul 20 23:08:50 qjamesbot-staging app/web.1: _eventsCount: 1,
Jul 20 23:08:50 qjamesbot-staging app/web.1: _maxListeners: undefined,
Jul 20 23:08:50 qjamesbot-staging app/web.1: _writableState: [Object],
Jul 20 23:08:50 qjamesbot-staging app/web.1: writable: false,
Jul 20 23:08:50 qjamesbot-staging app/web.1: allowHalfOpen: true,
Jul 20 23:08:50 qjamesbot-staging app/web.1: _transformState: [Object] },
Jul 20 23:08:50 qjamesbot-staging app/web.1: bodyUsed: false,
Jul 20 23:08:50 qjamesbot-staging app/web.1: size: 0,
Jul 20 23:08:50 qjamesbot-staging app/web.1: timeout: 0,
Jul 20 23:08:50 qjamesbot-staging app/web.1: _raw: [],
Jul 20 23:08:50 qjamesbot-staging app/web.1: abort: false } }

When I am searching the server status code 409 it states
https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
The request could not be completed due to a conflict with the current state of the target resource. This code is used in situations where the user might be able to resolve the conflict and resubmit the request.

The Smooch bot doesn't start anymore

Noticed recently that the smooch bot integration doesn't work. Smooch doesn't support that route anymore?

Request:

POST https://api.smooch.io/v1/init HTTP/1.1
Host: api.smooch.io
Connection: keep-alive
Content-Length: 384
Origin: http://sorin-cv-bot.herokuapp.com
x-smooch-sdk: web/3.15.2
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
app-token: ________________________
Content-Type: application/json
Accept: application/json
DNT: 1
Referer: http://sorin-cv-bot.herokuapp.com/
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,ro;q=0.8

{"userId":"","device":{"platform":"web","id":"________________________________","info":{"sdkVersion":"3.15.2","URL":"sorin-cv-bot.herokuapp.com","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36","referrer":"","browserLanguage":"en-US","currentUrl":"http://sorin-cv-bot.herokuapp.com/","currentTitle":""}}}

Response:

HTTP/1.1 404 Not Found
Date: Fri, 01 Feb 2019 08:50:55 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 133
Connection: keep-alive
Server: nginx/1.13.8
Vary: X-HTTP-Method-Override, Origin
Access-Control-Allow-Origin: http://sorin-cv-bot.herokuapp.com
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: Retry-After
Cache-Control: private, no-cache, no-store, must-revalidate
Expires: -1
Pragma: no-cache
ETag: W/"85-T7rlbbSI/uaihhE/TnktV3e+vE0"

{"error":{"code":"route_not_found","description":"There is no handler at this endpoint. Please ensure you've entered it correctly."}}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.