Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/facebook-example-botkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ controller.on('facebook_optin', function(bot, message) {
controller.on('message_received', function(bot, message) {
bot.reply(message, 'You are right when you say '+message.text);
});

controller.hears('hello world', 'message_received', function(bot, message) {
// add template tag to the next message sent
dashbot.addTemplateTag(message, 'hello-world');

bot.reply(message, 'hi');
});
11 changes: 10 additions & 1 deletion src/dashbot-facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ function DashBotFacebook(apiKey, urlRoot, debug, printErrors) {
that.urlRoot = urlRoot;
that.debug = debug;
that.printErrors = printErrors;
that.eventLogger = new EventLogger(apiKey, urlRoot, debug, printErrors)
that.eventLogger = new EventLogger(apiKey, urlRoot, debug, printErrors);
that.templateIds = {};

function logIncomingInternal(data, source, type) {
type = type || 'incoming'
Expand Down Expand Up @@ -66,6 +67,13 @@ function DashBotFacebook(apiKey, urlRoot, debug, printErrors) {
return that.eventLogger.logEvent(that.platform, data, 'npm');
}

that.addTemplateTag = function(message, templateId) {
if (!that.templateIds[message.channel]) {
that.templateIds[message.channel] = [];
}
that.templateIds[message.channel].push(templateId);
}

function getAndRemove(obj, prop) {
var temp = obj[prop];
delete obj[prop];
Expand Down Expand Up @@ -100,6 +108,7 @@ function DashBotFacebook(apiKey, urlRoot, debug, printErrors) {
access_token: bot.botkit.config.access_token
},
json: {
dashbotTemplateId: that.templateIds[message.channel] ? that.templateIds[message.channel].shift() : undefined,
recipient: {
id: channel
},
Expand Down