Created
February 2, 2017 11:21
-
-
Save alexandrenicol/836a8bfc3aaeb33c1f98ef31ef7607f0 to your computer and use it in GitHub Desktop.
Facebook Messenger Bot - Handle postback payload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Facebook = require('Facebook'); | |
exports.handler = (event, context, callback) => { | |
/* ... | |
Get messaging event // see https://gist.github.com/alexandrenicol/f01f867cb175cd89e3e100c508cc6f4a#file-index-js | |
... */ | |
// Iterate over each messaging event | |
entry.messaging.forEach(function(event) { | |
if (event.message) { | |
const message = event.message.text; | |
const senderID = event.sender.id; | |
Facebook.sendTextMessage(senderID, `you said: ${message}`); | |
} else if (event.postback) { | |
if (event.postback.payload === 'get_started'){ | |
Facebook.sendTextMessage(event.sender.id, `Welcome to the Weather station Bot`); | |
} else if (event.postback.payload === 'help'){ | |
Facebook.sendTextMessage(event.sender.id, `You can ask for the current temperature or humidity, either for your indoor or outdoor module`); | |
} else { | |
console.log("Webhook received unknown event: ", event); | |
} | |
} else { | |
console.log("Webhook received unknown event: ", event); | |
} | |
}); | |
}); | |
/*... | |
some code // see https://gist.github.com/alexandrenicol/f01f867cb175cd89e3e100c508cc6f4a#file-index-js | |
... */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment