Facebook chatbot with NodeJs mongoose and DialogFlow.
Plugin your facebook page token and DialogFlow token in tokens.js
- channel
- readWebhookEvent
- messagesGenerator
- eventsGenerator
- textMessage
- analyse
- create
- create
- create
- cityGenerator
- cityCollectionExists
- getUserDetails
- read
- updateUserMessages
- connect
Decides which module should respond to the req depending on the contents of req.
Parameters
Extract the webhook type
Parameters
eventObject event content
Returns String event type
Loops over the messages
Parameters
messagingObject array of messages
Loops over the events
Parameters
entryObject array of events
Registers user and message to database & sends message for analysis
Parameters
messagingJSON messaging event request
Uses apiai module to analyse input text
Parameters
Load the Tunisian city list from reference file to database
Add new message to database
Parameters
message_detailsobject The new message key/fields pairs
Creates new user or update existing users messages list
Parameters
user_detailsObject new user details according to user schemamessage_detailsObject new message details
Iterate over the list of cities from reference file
Look for cities collection in he current database
Returns object Resolves with true if the cities collection exists
Uses facebook API to request details about the user
Parameters
PSIDstring user unique id
Returns object a promise that resolves with the user details
Read user from database
Parameters
Returns Object User object if user exists or null otherwise
Adds a message to an existing user messages list
Parameters
userObject User database modeluser_detailsObject User to which add the message detailsmessage_detailsobject Message to add to user
Generates database connection and diconnects on process termination