

Copy the below piece of sample code in the Message Handler: 


response = Map();
info message;
if (operation.equals("chat")) {
    // First question from visitor
    response.put("action", "reply");
    response.put("replies", {
        {
            "text": "Hey! Got a question? I can help."
        }
    });
    options = {
        "Just browsing",
        "I want to buy",
        "I need assistance"
    };
    response.put("suggestions", options);
} else if (operation.equals("message")) {
    msg = message.get("text");
    if (msg.containsIgnoreCase("Just browsing")) {
        response.put("action", "context");
        response.put("context_id", "just_browsing");
        question1 = {
            "name": "product_list",
            "replies": {
                "Ok",
                "Great enjoy looking around,would you like me to tell you about our products?",
                "What would you like to know about?"
            },
            "input": {
                "type": "select",
                "options": {
                    "launched",
                    "Upcoming"
                }
            }
        };
        questions = Collection();
        questions.insert(question1);
        response.put("questions", questions);
    } else if (msg.containsIgnoreCase("I want to buy")) {
        response.put("action", "context");
        response.put("context_id", "buy");
        question1 = {
            "name": "product_buy",
            "replies": {
                {
                    "text": "Great what would you like to buy?"
                }
            },
            "input": {
                "type": "select",
                "options": {
                    "SUV",
                    "Truck",
                    "Hatchback",
                    "Sedan",
                    "Compact"
                }
            }
        };
        question2 = {
            "name": "owner",
            "replies": {
                {
                    "text": "Would you like to buy a new or a pre-owned vehicle?"
                }
            },
            "input": {
                "type": "select",
                "options": {
                    "Pre-owned",
                    "New"
                }
            }
        };
        questions = Collection();
        questions.insert(question1);
        questions.insert(question2);
        response.put("questions", questions);
    } else if (msg.containsIgnoreCase("I need assistance")) {
        response.put("action", "context");
        response.put("context_id", "assist");
        question1 = {
            "name": "how_assist",
            "replies": {
                {
                    "text": "How would you like me to assist you?"
                }
            },
            "suggestions": {
                "Book for servicing",
                "Raise a complaint",
                "Roadside assistance"
            }
        };
        questions = Collection();
        questions.insert(question1);
        response.put("questions", questions);
    } else if (msg.containsIgnoreCase("Yes,I'm interested")) {
        response.put("action", "context");
        response.put("context_id", "nextoptions");
        question1 = {
            "name": "nextrequest",
            "replies": {
                {
                    "text": "That's nice! What would you like me to do next ?"
                }
            },
            "suggestions": {
                "Book a test drive",
                "call back",
                " back to browsing"
            }
        };
        questions = Collection();
        questions.insert(question1);
        response.put("questions", questions);
    } else if (msg.containsIgnoreCase("Not now")) {
        response.put("action", "end");
    } else if (msg.containsIgnoreCase("Would you like to get notified on launch?")) {
        response.put("action", "context");
        response.put("context_id", "notified");
        questions = Collection();
        question1 = {
            "name": "email",
            "replies": {
                {
                    "text": "Can I have your email address?"
                }
            }
        };
        question2 = {
            "name": "contactnumber",
            "replies": {
                {
                    "text": "Thank You.Can I have your contact number?"
                }
            }
        };
        questions.insert(question1);
        questions.insert(question2);
        response.put("questions", questions);
    } else if (msg.containsIgnoreCase("Not now")) {
        response.put("action", "end");
    } else {
        response.put("action", "reply");
        response.put("replies", {
            {
                "text": "Hey! Got a question? I can help."
            }
        });
        options = {
            "Just browsing",
            "I want to buy",
            "I need assistance"
        };
        response.put("suggestions", options);
    }
}
return response;