botsgupshup

how to move to other section in script


I'm building a bot using gupshup.io using the scripting way ... but handling some things in default.js file as mentioned in the docs I'm trying in a handler function to check if the event.message equals specific string to go to another section in the script can anybody please help ? thanks a lot


Solution

  • So to achieve that you can create a child state to go another section and just set options.next_state to that state. I mean suppose you have a script like this

    [main]
        inputParser:Welcome to New Bot.
                thisFlow:
                    This is a output of this flow.
                callAnotherFlow:
                    :call default.anotherFlow
    [anotherFlow]
        This is another flow.[[Wow, No]]
            Wow
                Thanks
            No
                Oh!
    

    So in case if the message is 'another flow' you want the second flow to begin. So in the input parser you can create something like.

    module.exports.main = {
        inputParser: (options, event, context, callback)=>{
            if(event.message.toLowerCase() === "another flow"){
                options.next_state = 'callAnotherFlow';
            }else{
                options.next_state = 'thisFlow';
            }
            callback(options, event, context);
        }
    }
    

    I think this is what you are looking for.