2
votes

I'm newbie in coding and Watson Conversation and I'm trying to do a chatbot that schedule appointments from Monday to Saturday. I used @sys-date entity and it worked fine, but I don't know how to exclude sunday.For exemple:

watson: What is the best date for you?
user: sunday
watson: On this day the establishment is closed

I tried in the workspace: (condition) if: action=='sunday' like this: workspace

And coded like this in nodejs

    // Send the input to the conversation service

conversation.message(payload, function (err, data) {
  if (err) {
    return res.status(err.code || 500).json(err)
  }else if(data.output.action==='sunday'){
    var date = new Date();
  if(!(date.getDay() % 6)){
    return res.json(payload,data.output.text["On this day the establishment is closed"]);
  }}else{
  return res.json(updateMessage(payload, data));
}});});

And it still gives me the sunday date(ex. 23/04/2017). I know that everything is wrong, but I really tried.. can somebody help me, please? I'd appreciate if you could put the code to help me..

1
Please, provide a Minimal, Complete, and Verifiable example and not a picture of your code. Read the FAQs on how to post code.Clijsters
One thing I notice: (payload, data.output.text["Sunday"]) is using the comma operator, and in this case that just ends up the same as data.output.text["Sunday"]. So what did you want to do here?trincot
@trincot I tried to say: if user input sunday in the chat, the data.output.text would respond "On this day the establishment is closed" in the payload.. let me correct the code. tks!barbs
I don't know the API, but data.output.text["On this day the establishment is closed"] looks wrong. You probably need data.output.text = "On this day the establishment is closed"; as a separate statement, and then do res.json(updateMessage(payload, data));.trincot

1 Answers

1
votes

In this case, yes... You can use the parameter data to send message with Watson and with user. And, you cant exclude "Sunday" from System entities. This entitie is only for help us with special Conditions.

In your case, use:

data.output.text[0] = "On this day the establishment is closed";

Because data.output.text send Watson message to Conversation.

But, one best practicie for a good chatbot is create Intents and Entities to pass Intelligence for your bot and retain as much intelligence as possible in your chatbot. And your app will only check.

For example, create one Entitie @days with values Sunday, monday, etc.

  • Create one intent with examples how to ask "schedule appointments"
  • Create one Entitie @days with values Sunday, monday, etc.
  • Create one flow in your Dialog with Intent and Entitie condition (#bestDay and @days).

And in your Advance JSON, add one context variable with day value like this:

  {
  "context": {
    "day": "<? @days ?>"
  },
  "output": {
    "text": {
      "values": [
        "Sorry. On $day the establishment is closed"
      ],
      "selection_policy": "sequential"
    }
  }
}

Check the flow:

enter image description here

Check the flow works fine:

enter image description here

If not sunday:

enter image description here

Download the workspace to help you more here.