fb-messenger-bot-chat
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -42,9 +42,42 @@ #! /usr/bin/env node | ||
app.post('/sendApi', function(req, res) { | ||
console.log('get Message', req.body); | ||
// TODO Parse message | ||
pipe.send(req.body.message.text); | ||
pipe.send(req.body.message); | ||
res.status(200).send({}); | ||
}); | ||
app.post('/sendpayload', function(req, res) { | ||
var messages = [{ | ||
sender: { | ||
id: '0' | ||
}, | ||
recipient: { | ||
id: pageId | ||
}, | ||
timestamp: moment.valueOf(), | ||
postback: { | ||
mid: 'mid.' + ':' + "000000000000000000", | ||
seq: 232, | ||
payload: req.body.payload | ||
} | ||
}]; | ||
var messageFrame = { | ||
object: "page", | ||
entry: [{ | ||
id: pageId, | ||
time: moment.valueOf(), | ||
messaging: messages | ||
}] | ||
} | ||
// TODO Send messageFrame | ||
//console.log('send', messageFrame); | ||
request.post({url: defaultConfig.webhook, json: messageFrame}, function(err) { | ||
//console.log('yoyo2', err); | ||
}); | ||
res.status(200).send({}); | ||
}); | ||
app.post('/sendlocation', function(req, res) { | ||
@@ -51,0 +84,0 @@ |
{ | ||
"name": "fb-messenger-bot-chat", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Facebook Messenger Bot Send API implementation and chat simulator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -33,3 +33,3 @@ var angular = require('angular'); | ||
user: true, | ||
message: $scope.lat + ',' + $scope.lon | ||
message: {text: $scope.lat + ',' + $scope.lon} | ||
}); | ||
@@ -52,2 +52,12 @@ | ||
$scope.payload = function(reply) { | ||
$scope.messageLog.push({ | ||
user: true, | ||
message: {text: reply.title} | ||
}); | ||
ChatApi.payload(reply); | ||
} | ||
/* send message to bot */ | ||
@@ -59,3 +69,3 @@ $scope.send = function() { | ||
user: true, | ||
message: $scope.text | ||
message: {text: $scope.text} | ||
}); | ||
@@ -76,2 +86,4 @@ | ||
}); | ||
}); | ||
@@ -91,2 +103,8 @@ }); | ||
}, | ||
payload: function(data) { | ||
console.log('send payload', data); | ||
$http.post("/sendpayload", data).then(function(response) { | ||
console.log('sent..'); | ||
}); | ||
}, | ||
location: function(lat, lon) { | ||
@@ -93,0 +111,0 @@ console.log(lat, lon); |
@@ -21,4 +21,33 @@ module.exports = (config) => { | ||
/* send raw message (to: facebook id)*/ | ||
function send(to, message, cb) { | ||
function send(to, message, quick_replies, cb) { | ||
// quick_reply is optional | ||
if (_.isFunction(quick_replies)) { | ||
cb = quick_replies; | ||
} else if (_.isArray(quick_replies) && quick_replies.length > 0) { | ||
message.quick_replies = quick_replies.map(function(reply) { | ||
var payload = reply.payload; | ||
// payload processing | ||
if (!_.isString(reply.payload) && _.isObject(reply.payload)) { | ||
try { | ||
payload = JSON.stringify(reply.payload); | ||
} catch (e) { | ||
payload = reply.toString(); | ||
} | ||
} | ||
return { | ||
content_type: 'text', | ||
title: reply.text, | ||
payload: payload | ||
} | ||
}); | ||
} | ||
request({ | ||
@@ -42,16 +71,3 @@ url: defaultOptions.sendApiUrl, | ||
// quick_reply is optional | ||
if (_.isFunction(quick_replies)) { | ||
cb = quick_replies; | ||
} else if (_.isArray(quick_replies) && quick_replies.length > 0) { | ||
message.quick_replies = quick_replies.map(function(reply) { | ||
return { | ||
content_type: 'text', | ||
title: reply.text, | ||
payload: reply.payload | ||
} | ||
}); | ||
} | ||
send(to, message, cb); | ||
send(to, message, quick_replies, cb); | ||
} | ||
@@ -61,2 +77,3 @@ | ||
function cards(to, cards, quick_replies, cb) { | ||
var message = { | ||
@@ -72,17 +89,3 @@ attachment: { | ||
// quick_reply is optional | ||
if (_.isFunction(quick_replies)) { | ||
cb = quick_replies; | ||
} else if (_.isArray(quick_replies) && quick_replies.length > 0) { | ||
message.quick_replies = quick_replies.map(function(reply) { | ||
return { | ||
content_type: 'text', | ||
title: reply.text, | ||
payload: reply.payload | ||
} | ||
}); | ||
} | ||
send(to, message, cb); | ||
send(to, message, quick_replies, cb); | ||
} | ||
@@ -99,3 +102,3 @@ | ||
} | ||
if (!message || !message.sender || !message.sender.id) { return recognizedMessage; } | ||
@@ -124,3 +127,9 @@ | ||
recognizedMessage.type = 'postback'; | ||
recognizedMessage.data = message.message.quick_reply.payload; | ||
// parse json | ||
try { | ||
recognizedMessage.data = JSON.parse(message.message.quick_reply.payload); | ||
} catch (e) { | ||
recognizedMessage.data = message.message.quick_reply.payload; | ||
} | ||
} | ||
@@ -132,3 +141,9 @@ } | ||
recognizedMessage.type = 'postback'; | ||
recognizedMessage.data = message.postback.payload; | ||
// parse json | ||
try { | ||
recognizedMessage.data = JSON.parse(message.postback.payload); | ||
} catch (e) { | ||
recognizedMessage.data = message.postback.payload; | ||
} | ||
} | ||
@@ -135,0 +150,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18333
398