Created
December 23, 2016 04:16
-
-
Save anonymous/0ffb2985b0c22663337469694e37a49f to your computer and use it in GitHub Desktop.
wit.ai bot engine app
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
| var messengerSend = require('messengerSend'); | |
| // ------------------------------------------------------------ | |
| // Actions | |
| var actions = { | |
| send: send, | |
| addTopics: addTopics, | |
| getQuestion: getQuestion, | |
| findPriorDiscussions: findPriorDiscussions, | |
| compileEbook: compileEbook | |
| } | |
| function send(request, response) { | |
| var message = {}; | |
| if (response.text) { | |
| message.text = response.text; | |
| } | |
| if (response.quickreplies) { | |
| message.quick_replies = response.quickreplies.map( | |
| function(reply) { | |
| return { | |
| content_type: 'text', | |
| title: reply, | |
| payload: reply, | |
| }; | |
| } | |
| ) | |
| } | |
| messengerSend({ | |
| recipient: {id: request.fbid}, | |
| message: message, | |
| }); | |
| } | |
| function addTopics(request) { | |
| request.action = 'addTopics'; | |
| return fetchFromServer(request); | |
| } | |
| function getQuestion(request) { | |
| request.action = 'getQuestion'; | |
| return fetchFromServer(request); | |
| } | |
| function findPriorDiscussions(request) { | |
| request.action = 'findPriorDiscussions'; | |
| return fetchFromServer(request); | |
| } | |
| function compileEbook(request) { | |
| request.action = 'compileEbook'; | |
| return fetchFromServer(request); | |
| } | |
| function fetchFromServer(request) { | |
| console.log(JSON.stringify(request, null, 4)); | |
| var obj_str = JSON.stringify(request); | |
| return fetch('https://monolog.chat', { method: 'POST', body: obj_str }) | |
| .then(function(res) { | |
| return res.json(); | |
| }).then(function(json) { | |
| console.log(json); | |
| console.log(JSON.stringify(json, null, 4)); | |
| return json.context; | |
| }); | |
| } | |
| // ------------------------------------------------------------ | |
| // Helpers |
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
| {"title":"monolog","previousVersions":["5a387f6ccb4be4a1f77f2113747a558a","bf12dcb15e8503381d2ebf33a8b252fe","fe17fb1c27bbd4a5c7fd6ed339b394a1","b5b2f940dacc8cfa16b082686b29086c","54247226620f91bcb5126ed7df990cf3","6e49e4c399e3a2177b15f9a1d72ec723","c90b518e5389c337fe24051c24d4b3f6","623c80b4fee5f84f741e21eeb4cb65f3"]} |
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
| OQ5DZIMO6Z4AEHFGHXXPS3R2TLBPWBPD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment