Giter Site home page Giter Site logo

smooch-bot-example's Introduction

SmoochBot Examples

A set of example chat bots built on smooch/smooch-bot.

Before you get started with any of these samples, from this directory you should:

$ npm install

All of these samples use the same scipt defined in script.js. Feel free to play around with it as you go.

Console Example (/console)

This is the simplest sample that runs via the command line and uses an in-memory store to track state.

console

To run it, simply:

$ node console

And start chatting with your bot on the command line.

Heroku Example (/heroku)

This is an Express app that uses the Smooch web widget to provide the chat interface. The app makes use of SmoochApiStore and SmoochApiBot to persist conversation state and user properties via Smooch.

heroku

To deploy your own:

  1. First, sign up for a free account at smooch.io

  2. With a new Smooch app created, go to the settings tab and take note of your App Token. Also, generate a new Secret Key, and take note of the key ID and secret.

    settings

  3. Deploy your app to Heroku using the button below. You'll need to specify your app token, key ID, and secret in the app's SMOOCH_APP_TOKEN, SMOOCH_KEY_ID, and SMOOCH_SECRET config settings.

    Deploy

  4. Your app should now be running on Heroku but you're not quite done yet. Take note of the URL where your heroku app is running, for example https://foo-bar-4242.herokuapp.com. You'll need to specify this in your heroku app SERVICE_URL config variable. You can do this in the Heroku control panel under Settings > Config Variables, or if you have the Heroku Toolbelt installed you can do it like so:

     $ heroku config:set SERVICE_URL=https://foo-bar-4242.herokuapp.com -a foo-bar-4242
    
  5. You should be all set. Open your Heroku app and start chatting with your new bot!

  6. Bonus: Open the Smooch control panel and add more integrations. You can add new user channels like Twilio SMS, or you can add Slack or HipChat which will let you join in on the conversation along side your bot. Pretty neat!

slack

Troubleshooting your bot

Is your bot misbehaving? Not working? Here are some steps you can follow to figure out what's going wrong.

Warning: command line instructions incoming. You may not be accustomed to using the command line but don't worry, it's much easier than you think.

Check your bot's logs on heroku

If there's a bug in your code, checking the heroku logs is the best way to figure out what's going wrong. Here's how:

  1. Install the heroku toolbelt: https://toolbelt.heroku.com/ These are power tools that let you do a lot more than what Heroku dashboard alone allows.

  2. Next, open your preferred terminal app. On OSX the default Terminal app will work fine here.

  3. Log in to the heroku toolbelt with the following command:

     heroku login
    

    If the command heroku isn't found, try restarting your terminal app. Once logged in you should be able to list all of your heroku apps like so:

     heroku apps
    

    which should give you something like this:

     $ heroku apps
     === My Apps
     your-app
    
  4. Now you can check the logs of your heroku app like so:

     heroku logs -a your-app
    

    This will give you a dump of your most recent app logs. They will look something like the following. Can you spot the error below?

     2016-05-09T14:08:34.966358+00:00 heroku[slug-compiler]: Slug compilation started
     2016-05-09T14:08:34.966363+00:00 heroku[slug-compiler]: Slug compilation finished
     2016-05-09T14:08:34.946344+00:00 heroku[web.1]: State changed from up to starting
     2016-05-09T14:08:34.945605+00:00 heroku[web.1]: Restarting
     2016-05-09T14:08:37.860802+00:00 heroku[web.1]: Stopping all processes with SIGTERM
     2016-05-09T14:08:39.493078+00:00 heroku[web.1]: Process exited with status 143
     2016-05-09T14:08:41.182450+00:00 heroku[web.1]: Starting process with command `npm start`
     2016-05-09T14:08:45.818995+00:00 app[web.1]:
     2016-05-09T14:08:45.819017+00:00 app[web.1]: > [email protected] start /app
     2016-05-09T14:08:45.819018+00:00 app[web.1]: > node heroku
     2016-05-09T14:08:45.819019+00:00 app[web.1]:
     2016-05-09T14:08:46.601444+00:00 app[web.1]: module.js:433
     2016-05-09T14:08:46.601454+00:00 app[web.1]:     throw err;
     2016-05-09T14:08:46.601455+00:00 app[web.1]:     ^
     2016-05-09T14:08:46.601456+00:00 app[web.1]:
     2016-05-09T14:08:46.601457+00:00 app[web.1]: SyntaxError: /app/script.json: Unexpected token }
     2016-05-09T14:08:46.601458+00:00 app[web.1]:     at Object.parse (native)
     2016-05-09T14:08:46.601458+00:00 app[web.1]:     at Object.Module._extensions..json (module.js:430:27)
     2016-05-09T14:08:46.601459+00:00 app[web.1]:     at Module.load (module.js:357:32)
     2016-05-09T14:08:46.601460+00:00 app[web.1]:     at Function.Module._load (module.js:314:12)
     2016-05-09T14:08:46.601460+00:00 app[web.1]:     at Module.require (module.js:367:17)
     2016-05-09T14:08:46.601461+00:00 app[web.1]:     at require (internal/module.js:20:19)
     2016-05-09T14:08:46.601462+00:00 app[web.1]:     at Object.<anonymous> (/app/script.js:6:21)
     2016-05-09T14:08:46.601473+00:00 app[web.1]:     at Module._compile (module.js:413:34)
     2016-05-09T14:08:46.601474+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:422:10)
     2016-05-09T14:08:46.601474+00:00 app[web.1]:     at Module.load (module.js:357:32)
    

    Did you notice the SyntaxError part? It looks like there's a problem in my script.json. If I inspect that file in github I'll see that indeed, I have a stray comma at the end if the second to last line.

    image

    After I remove that comma and redeploy, everything will return to normal.

How do I deploy my fixes to Heroku?

Great question! Now that you've found your bug and fixed it, you want to redeploy your app. With Heroku you can trigger a deployment using git. Without going into detail, git is a code versioning system it's where github gets its name. Git is the software, github.com is a separate company that hosts git code repositories. If you're using a Mac you should already have git installed. Although git is a very complex tool, it's worth learning if you're eager, but for this guide's purposes we'll be using only the most basic concepts of git, pulling changes from a remote github repository, commiting changes, and then pushing those changes out to a remote repository.

  1. To deploy using git you first have to download a copy of your heroku app's code, like so:

     git clone https://github.com/your-github-username/your-app
    

    Note that git will prompt you to enter your github credentials.

  2. This will create a new git copy of your code in a new folder. You can go into that folder like so:

     cd your-app
    
  3. Now you can use the heroku toolbelt to link this git copy up to your heroku app with the following command:

     heroku git:remote -a your-app
    
  4. Once that's done, you can now deploy to heroku directly from this directory. If you've made any fixes on github directly, be sure to sync them here like so:

     git pull origin master
     git push heroku master
    
  5. You can also make changes to your local copy of the code. To do this, edit whatever file you wish in your preferred text editor, and then commit and push them up to github. You'll add a commit message, which is a short sentence decribing what you changed.

     git commit -a -m 'Your commit message'
     git push origin master
    

    Then, you can deploy those changes to heroku in the same way:

     git push heroku master
    

smooch-bot-example's People

Contributors

alavers avatar esthercrawford avatar skx 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  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  avatar  avatar

smooch-bot-example's Issues

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.

Uncaught (in promise) Error at o (shallowEqual.js:18)

Smooch web widget not loading.
I am getting this when inspecting element.

image

Failed to load resource: the server responded with a status of 401 ()
shallowEqual.js:18 Uncaught (in promise) Error
    at o (shallowEqual.js:18)

Any feeback please.

Passing a param from heroku/index.js to a certain state in script.js

Hi there.

I wanna know how can I pass a param/argument from heroku/index.js to a certain state in script.js

I have done like below

heroku.index

Promise.all([
        stateMachine.bot.releaseLock(),
        stateMachine.setState(ai_action), // set new state ADD_MOVIE
        stateMachine.receiveMessage(params.movie_keywords) // calling receive of ADD_MOVIE state and passing a string param i.e params.movie_keywords = "my_string"
    ]);
    res.end();

and in script.js I have defined an state named ADD_MOVIE here is the code

ADD_MOVIE : {
        receive: (bot, message) => {
            const movie_name_searched = message.text;
            console.log("movie_name_searched : "+ movie_name_searched);  // I am getting undefined here
        }
    }

QUESTION

What I am missing here. Am I doing any thing wrong here. please help. I wanna pass the param value from heroku/index.js to my ADD_MOVIE recieve state in script.js.

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

how to get last bot state

Hello,

Is there any way to get the last state executed by the bot. Like

let say I have states defined for my bot are given below.

ASK_NAME:
ASK_EMAIL:
ASK_ADDRESS:

ASK_NAME executed successfully then bot is on ASK_EMAIL state, Can I get the last executed state was ASK_NAME, is there any way to get this?

Regards
Qadir Hussain

Get message from slack/frontApp and do some processing!

Hi there!

Sorry for the bad title, Let me explain.

First thing to tell you is We have configured Slack as my Receiving channel (business end, Later we will configure the frontApp and many others).

We are developing our contact-us (live chat/ Support) page. We want both the Bot and Human agent can answer our customer's queries. Human should answer the queries which a bot is unable to understand. We have done this already by using the bot.setProp('silent', true). Whenever our customer asks a query, we first check it either it can be handled by our bot (with certain AI) or not. IFF yes then bot will simply answer the query. IFF not we redirect our customer to our live human agent by simply setting the bot.setProp('silent', true).

Now here comes the climax. Now bot is Turned OFF and our Human Agent (on Slack) is chatting with our customer live. Now If customer asks an query which can be handled by our bot, Is there any way that our Human Agent (on slack) can turn the bot ON by simply setting bot.setProp('silent', false).

QUESTION IN SHORT:
Is there any way to process the messages from Slack/FrontApp (or any business end). So that we can turn the Bot ON.

Bot states inconsistent with multiple user messages.

Whenever the user messages multiple lines quickly the bot behaves unpredictably by either restarting the current state, skipping the next designated state, or sometimes partially executing a state in attempts to read in the user's stream of messages.

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?

Deploy to AWS Lambda

Hi,

Would this bot work on a serverless architecture such as AWS Lambda?

Thanks

smooch Bot /help menu implementation

Can we implement bot /help menu in using smooch

See image below for example in telegram
telegram chat

Is this possible? Please suggest me any pointers and directions for this.

How this work?
User typed "/" bot will show the available help menu as a autocomplete menu

Question

More of a question than an issue. When you create an action button like

%[Button Text](postback:button action)

How do you specify the handler for the postback. What does "button action" map to? Can you show an example?

UI for creating conversation?

Hello. I am able to use the chatbot. Now, I need to setup the conversation, and I find doing it by code a bit counterproductive. Is there an easier way to do this? like here EstherBot

smooch-bot not replying

Hi,
I tried setting up smooch-bot via the Heroku example. I open the heroku app and chat with the bot, but I don't receive any replies. The messages I type are being forwarded to smooch because I am receiving email notifications...but no replies from smooch-bot in the chat window.

I am not a programmer and try to follow the directions. I am deploying the app via dropbox connection. Is it normal that the Heroku folder in my dropbox is empty? I tried to uploading script.js into Dropbox>Apps>Heroku and Dropbox>Apps>Heroku>mybot...but no replies. I am not sure where I went wrong, could you help me point in the right direction?

Thank you for your help in advance!

Restarting the bot conversation

I cloned this repo and am building a bot which is running in a web embedded widget. Since I'm in development mode, I need a way to explicitly call start in the script.js as a way to "restart" my bot script when I add or change functionality.

Is there a way I can control calling the start prompt method programmatically?

start: {
    prompt: (bot) => {
        return bot.say(`Hey, I'm a robot! Just going to ask you a few questions before you get started...`)
            .then(bot.say(`First up: what's your full name?`))
    },
    receive: function (bot, message) {
        const name = message.text;
        const firstName = name.split(' ').slice(0, -1).join(' ');
        return bot.setProp('name', name)
            .then(() => bot.say(`Nice to meet you ${firstName}!`))
            .then(() => 'getRole');
    }
},

[REQUEST]

Please you could add, structured messages and carousel messages.

Changing Script

Hi!

I'm running the heroku app locally and I altered the wording of the script. However, the changes do not appear in the conversation I have with the bot, regardless of whether i restart it or not. Could it be that the app is somehow pulling the original script from an api externally because even if I comment out the whole script it continues to have the same convo flow.

Look forward to hearing from one of you.

Cannot send message to our customer when customer did not write first. :(

let say we have a customer using our iOS app (smooch iOS SDK is integrated) but he/she didn't sent a message via smooch chat widget (or via any other messaging channel). is there any way to know that new customer has started using our app, so that we can start conversation with them by sending her a message saying greetings

basically the question is How to send a message (smooch) to our customer initiated by us via slack and/or front?

Fred said this on Smooch support
Hi there! Starting a conversation with a user will only work with whispers. We don’t offer a way to start conversation through business systems since it would require we create channels for every init in your app (it would be too heavy for you to handle)

But

Whispers will initiate the chat with the customer once he/she send us reply. If he/she didn't replied back we can't init the chat with our customer. And that's why whispers will fail in this situation too.

We do need a way to start conversation with our customers through business systems anyhow. we can handle all that heavy stuff.
Please give any suggestion/direction or any hack to to this. Thanks

Can we do this something like using slack api? like what happens when a new user send us a message? A new channel is created and a user joins that channel. right?

I have successfully created a channel in slack via slack api. here is the code.

https://www.dropbox.com/s/r27fd6t8pii2qip/Screenshot%202017-03-27%2013.54.54.png?dl=0

Reply button in web embedded widget opens new browser tab on click

I'm outputting a "Reply Button" to the conversation using the following code:

getRole: {
    prompt: (bot) => bot.say(`What's your primary role at your company? %[Agent](reply:agent) %[Team Manager](reply:team) %[Broker](reply:broker)`),
    receive: (bot, message) => {
        return bot.setProp('role', message.text)
            .then(() => bot.say(`Thanks!`))
            .then(() => 'getBusinessType');
    }
},

When one of the Reply buttons is clicked a new browser tab opens instead of the reply value being added to the conversation. After inspecting the DOM I noticed the Reply buttons are actually being output as anchors with target="_blank".

Smooch Webhook - Bad Request

After 2016-10-21, I am not being able to create new webhooks and obtaining the following error running heroku web local:

2:52:17 PM web.1 |  > [email protected] start smooch-bot-example
2:52:17 PM web.1 |  > node heroku
2:52:19 PM web.1 |  Smooch Bot listening at http://:::5000
2:52:20 PM web.1 |  Error creating Smooch webhook: { Error: Bad Request
2:52:20 PM web.1 |      at handleStatus (/smooch-bot-example/node_modules/smooch-core/lib/utils/http.js:45:17)
2:52:20 PM web.1 |      at process._tickCallback (internal/process/next_tick.js:103:7)
2:52:20 PM web.1 |    response: 
2:52:20 PM web.1 |     Body {
2:52:20 PM web.1 |       url: 'https://api.smooch.io/v1/webhooks',
2:52:20 PM web.1 |       status: 400,
2:52:20 PM web.1 |       statusText: 'Bad Request',
2:52:20 PM web.1 |       headers: Headers { _headers: [Object] },
2:52:20 PM web.1 |       ok: false,
2:52:20 PM web.1 |       body: 
2:52:20 PM web.1 |        PassThrough {
2:52:20 PM web.1 |          _readableState: [Object],
2:52:20 PM web.1 |          readable: true,
2:52:20 PM web.1 |          domain: null,
2:52:20 PM web.1 |          _events: [Object],
2:52:20 PM web.1 |          _eventsCount: 1,
2:52:20 PM web.1 |          _maxListeners: undefined,
2:52:20 PM web.1 |          _writableState: [Object],
2:52:20 PM web.1 |          writable: false,
2:52:20 PM web.1 |          allowHalfOpen: true,
2:52:20 PM web.1 |          _transformState: [Object] },
2:52:20 PM web.1 |       bodyUsed: false,
2:52:20 PM web.1 |       size: 0,
2:52:20 PM web.1 |       timeout: 0,
2:52:20 PM web.1 |       _raw: [],
2:52:20 PM web.1 |       _abort: false } }
2:52:20 PM web.1 |  Error: Bad Request
2:52:20 PM web.1 |      at handleStatus (/smooch-bot-example/node_modules/smooch-core/lib/utils/http.js:45:17)
2:52:20 PM web.1 |      at process._tickCallback (internal/process/next_tick.js:103:7)

However, using the bearer token created by the application, I successfully create a webhook using curl (as described at Smooch documentation).

curl https://api.smooch.io/v1/webhooks \
     -X POST \
     -d '{"target": "http://example.com/callback"}' \
     -H 'content-type: application/json' \
     -H 'authorization: Bearer your-jwt'

Question: Customization and typing indicator

Not so much an issue, more a question on how to use smooch bot to recreate your Smooch conversational onboarding experience (which I love!).

Your onboarding UI is full screen and starts immediately with a question. Then before each reply from your bot a typing indicator is shown. Can all this (full screen, let the bot initiate the conversation and show a typing indicator) be achieved with this framework?

Any help or pointers would be greatly appreciated! In any case this is awesome stuff!

App crash on PROD heroku

Hi there,

I have created two separate smooch apps. names as. qBotStaging , qBotLive.
qBotStaging is configured with my Heroku-staging and qBotLive is configured with my Heroku-live.
both of my heroku (i.e Heroku-staging & Heroku-live) has the same code . App is working fine on Heroku-staging but its crashing on Heroku-live.

Here is the log

2017-01-12T07:32:25.285191+00:00 app[web.1]: trigger : message:appUser
2017-01-12T07:32:25.285294+00:00 app[web.1]: case message:appUser
2017-01-12T07:32:25.285350+00:00 app[web.1]: user message: {Hi there}
2017-01-12T07:32:25.649184+00:00 app[web.1]: Caught! Bad Request
2017-01-12T07:32:27.622990+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/webhook" host=qjamesbot.herokuapp.com request_id=aa815dce-6000-4ee2-a5e8-18b0e2ee5533 fwd="54.91.11.7" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0

log of statging => Catch not executed even silent property is undefined.

2017-01-12T07:28:21.851935+00:00 app[web.1]: trigger : message:appUser
2017-01-12T07:28:21.851959+00:00 app[web.1]: case message:appUser
2017-01-12T07:28:21.852087+00:00 app[web.1]: user message: {hi}
2017-01-12T07:28:22.268759+00:00 app[web.1]: isBotSilent : undefined
2017-01-12T07:28:37.198704+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/webhook" host=qjamesbot-staging.herokuapp.com request_id=a3a6b1b6-d55c-4339-804b-bcc4afb048ab fwd="54.91.11.7" dyno=web.1 connect=0ms service=30003ms status=503 bytes=0

Here is my code of heroku/index.js where it crashed

//Check bot isBotSilent
    stateMachine.bot.getProp('silent')
    .then((isBotSilent) => {
        console.log("isBotSilent : "+isBotSilent); // In staging this log prints but on live heroku its not and catch is executed
    }).catch(function(error) {
        console.log('Caught!', error.message);
    });

Please help. ASAP, its 3rd day I m stuck on this.

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.