diff --git a/examples/facebook-example-botkit.js b/examples/facebook-example-botkit.js index c39654b..3e192ae 100644 --- a/examples/facebook-example-botkit.js +++ b/examples/facebook-example-botkit.js @@ -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'); +}); diff --git a/src/dashbot-facebook.js b/src/dashbot-facebook.js index 9189729..37313ed 100644 --- a/src/dashbot-facebook.js +++ b/src/dashbot-facebook.js @@ -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' @@ -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]; @@ -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 },