Search code examples
dialogflow-esactions-on-googledialogflow-es-fulfillment

How to pass information from one intent to another


Using Google Sign in for Account linking , I have read user email. How do i pass this conversation data to the next intent?


app.intent("Get Signin",(conv , params, signin) =>{
    if(signin.status === 'OK'){
        const email = conv.user.email
        conv.ask(`I got your email as ${email}. How would you like to redeem?`)
        conv.ask(new Suggestions(['QR code'],['16 digit code'],['Cancel']))
    }
    else
    {
        conv.close("Please sign in to redeem");
    }
})





app.intent("numcode",(conv,{num, points}) => {
    const mailOptions = {
        from: "abc", 
        to: email, 
        subject: "YAY!", 
        html: `<p>Hello !! <br> You have ${points} in (${num}). </p>`
    }
    transporting.sendMail(mailOptions, (err, info) => {
        if(err)
        {
          console.log(err);
        }
    })
    conv.ask("You have succesfully finished.");
})

I want to send a mail to the user , so what should be replaced with "to: email" or what should be added to my code.


Solution

  • You don't have to pass it to your next intent. Once your user is signed in via accountlinking the user's email is available via the conv object. You can call conv.user.email to retrieve it. When your user triggers your numcode intent, it should fill the to property with the user's email.

    In your mail options you can do the following:

    const mailOptions = {
            from: "abc", 
            to: conv.user.email, 
            subject: "YAY!", 
            html: `<p>Hello !! <br> You have ${points} in (${num}). </p>`
        }