Skip to main content Link Search Menu Expand Document (external link)

Listen to Inbound Message

  • Details
    • Listen to inbound message and decide new step
    • Sets the handler for next message from User, with more options to handover to multiple handlers based on conditions.

$.listen ( defaultHandler )

  • defaultHandler - default handler for user response
      // Listen to current inbound message
     $.listen(postCredit);
      // First reply and then Listen to current inbound message
     $.reply({
       text :  {
         body : `So you are ${inbound.getText()}`
        }
     }).listen(postCredit);
    

$.listen ( conditions… )

  • condition.text (optional) - Match Exact Text
  • condition.code (optional) - Match Button Code
  • condition.pattern (optional) - Match with regex
  • condition.handler - handler for user response<

Match Exact Text

  $.listen({
    text : "Good",
    handler : goodHandle  //If answer is "Good"
  },{
    text : "Bad",
    handler : badHandle //If answer is "Bad"
  },otherHandle); // If answer is none of the above, this is default handler

Match with regex

  $.listen({
    pattern : /good/i,
    handler : goodHandle  //If answer is "Good"
  },{
    pattern : /bad/i,
    handler : badHandle //If answer is "Bad"
  }, otherHandle); // If answer is none of the above, this is default handler

Match Button Code

  $.reply({
    text :  {
      body : "Hi, I am good how are you?"
     },
     options : {
       buttons : [
        { code : "good", label : "Good"},
        { code : "bad", label : "Bad"}
      ] //Pass text as options
     }
  }).listen({
    code : "good",
    handler : goodHandle  //If answer is "Good"
  },{
    code : "bad",
    handler : badHandle //If answer is "Bad"
  },otherHandle); // If answer is none of the above, this is default handler

Match Intent

  $.listen({
    intent : "good",
    handler : goodHandle  //If intent is "Good"
  },{
    intent : "bad",
    handler : badHandle //If intent is "Bad"
  },otherHandle); // If answer is none of the above, this is default handler


Table of contents