0

Hi I am making a new bot for a product where I need to ask customer login id and password.

So for my case, user would initiate a conversation by typing hi then bot will reply Hey! How can I help you, here if customer enter I want to transfer money then bot will respond Please enter a login ID, first here customer will enter login id and bot will respond Enter your password then it goes like this.

I have done like below in node js which seems not a correct way to me.

app.post('/webhook/', function (req, res) {

    let messaging_events = req.body.entry[0].messaging
    for (let i = 0; i < messaging_events.length; i++) {
        let event = req.body.entry[0].messaging[i]
        let sender = event.sender.id
        if (event.message && event.message.text) {
            let text = event.message.text.toLowerCase();
            var greets = ['hi', 'hey', 'hello', 'good morning', 'good evening']
            if(greets.indexOf(text) > -1) {
                sendTextMessage(sender, 'Hey! How can I help you ?')
            }
            else if((text.indexOf('money transfer') > -1) || (text.indexOf('transfer money') > -1)) {
                sendTextMessage(sender, 'OK. Please enter your login details.')
                lastMessage = 'Please enter your login ID.'
            } else if(text.indexOf('restart') > -1) {
                lastMessage = ''
                sendTextMessage(sender, 'Thanks, Give a seconds to me :)')
            }
            else {
                sendTextMessage(sender, 'Huh! Uhhh broke me :(')
            }
        } else if (event.postback) {
            var payload = event.postback.payload;
            if(payload) {
                // When a postback is called, we'll send a message back to the sender to 
                // let them know it was successful.
                // do nothing
                switch (payload) {
                    case 'USER_DEFINED_PAYLOAD':
                        sendTextMessage(sender, 'Welcome to XXX, What are you looking for today ?')
                        break;
                }
            }
            console.log("Postback received: " + JSON.stringify(event.postback));
        }
    }
    res.sendStatus(200)
})

What is the best way to achieve my case, how flow will be maintained if user enter a login id then bot would ask for password.

Thanks in advance.

N Sharma
  • 33,489
  • 95
  • 256
  • 444

2 Answers2

3

I don't think asking for user and password in plain text message it isn't secure way to be implemented, also bad user experience.

Instead, provide an external link for user login process

or take a look at

Account Linking
https://developers.facebook.com/docs/messenger-platform/account-linking

Account Linking starts a authentication process allowing a Messenger user to log-in using your own authentication flow, and link his or her business account.

  • I don't think Account Linking works? any samples that work in real life? https://github.com/Microsoft/BotBuilder/issues/2274 – MrOnyancha Feb 16 '17 at 05:39
0

I think the best way is send a external link to customer, or send a structured message with a url button that customer could click and link to outside. So your external link should bring user's sender_id. Once your customer has logged in at external link, your callback function could then tell bot to send a login success! message, then you can continue the conversation.

Hui-Yu Lee
  • 909
  • 8
  • 20