嗨我正在爲產品製作新的機器人,我需要詢問客戶的登錄ID和密碼。Conversation facebook messenger bot
所以對我而言,用戶將啓動一個會話通過鍵入hi
那麼機器人就會回覆Hey! How can I help you
,這裏如果顧客進入I want to transfer money
然後機器人將響應Please enter a login ID
,先在這裏的客戶將進入登錄ID和機器人會迴應Enter your password
那麼它是這樣這個。
我在節點js中做了如下,這似乎不是對我來說正確的方式。
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)
})
什麼是最好的方式來實現我的情況,如何保持流量,如果用戶輸入登錄ID然後機器人會要求輸入密碼。
在此先感謝。
有沒有辦法做到這一點沒有信使機器人外重定向? – MrOnyancha