Search code examples
watson

Watson Conversation - Getting Dialog Context to Application


I've connected my chatbot (Watson Conversation) to messenger. However, I'm stuck on passing of context variable for my Google Map API.

Process Flow:

  1. User: I want to compute the distance
  2. Bot: Gets $var1 and $var2
  3. User: Inputs $var1 and $var2
  4. Bot: Provides the distance between $var1 and $var2

How will I be able to get the user's $var1 and $var2 on my Application Code?

Note: It is on Dialogue Node [2].


Solution

  • For java just simply use :

        Conversation service = new Conversation("2017-07-13");
        service.setUsernameAndPassword("", "");
        MessageOptions newMessage = new MessageOptions.Builder().workspaceId("")
                .input(new 
        InputData.Builder(input).build()).context(context).build();
        MessageResponse response = service.message(newMessage).execute();
        int var1 = response.getContext().get("$var1");
    

    Similarly for 2nd variable.