diff --git a/README.md b/README.md index 1ed82a7..32b86da 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ - [sendButtons (options[, callback])](#sendbuttons-options-callback) - [sendGeneric (options[, callback])](#sendgeneric-options-callback) - [sendReceipt (options[, callback])](#sendreceipt-options-callback) - - [setWelcomeScreen (options[, callback])](#setwelcomescreen-options-callback) + - [setGetStarted (options[, callback])](#setgetstarted-options-callback) - [setPersistentMenu (options[, callback])](#setpersistentmenue-options-callback) - [getUserProfile (userId[, callback])](#getuserprofile-userid-callback) - [createWebURLButton (title, url)](#createweburlbutton-title-url) @@ -184,18 +184,16 @@ botly.sendReceipt({id: sender, payload: payload}, function (err, data) { }); ``` -#### setWelcomeScreen (options[, callback]) +#### setGetStarted (options[, callback]) ```javascript -botly.setWelcomeScreen({pageId: "myPage", message: { - text: "Welcome to my page!" -}}, function (err, body) { +botly.setGetStarted({pageId: "myPage", payload: "GET_STARTED_CLICKED"}, function (err, body) { //log it }); ``` #### setPersistentMenu (options[, callback]) ```javascript -botly.setWelcomeScreen({pageId: "myPage", buttons: [botly.createPostbackButton('reset', 'reset_me')]}, function (err, body) { +botly.setPersistentMenu({pageId: "myPage", buttons: [botly.createPostbackButton('reset', 'reset_me')]}, function (err, body) { //log it }); ``` @@ -275,3 +273,4 @@ botly.on("error", (ex) => { - added support for quick replies - add support for persistent menu - added support for audio/video/file attachments +- renamed setWelcomeScreen to setGetStarted since no longer supported by facebook. diff --git a/example/app.js b/example/app.js index edc788a..99e4917 100644 --- a/example/app.js +++ b/example/app.js @@ -6,7 +6,7 @@ const path = require('path'); const bodyParser = require('body-parser'); const http = require('http'); -const port = '3000'; +const port = '8080'; const Botly = require("../index"); const botly = new Botly({ @@ -50,6 +50,11 @@ botly.on('message', (sender, message, data) => { console.log("send generic cb:", err, data); }); } + else if (data && data.text && data.text.indexOf("quick") !== -1) { + botly.sendText({id: sender, text:"some question?", quick_replies: [botly.createQuickReply('option1', 'option_1')]}, function (err, data) { + console.log("send generic cb:", err, data); + }); + } else if (data && data.text && data.text.indexOf("receipt") !== -1) { let payload = { "recipient_name": "Stephane Crozatier", @@ -117,7 +122,7 @@ botly.on('message', (sender, message, data) => { botly.getUserProfile(sender, function (err, info) { users[sender] = info; - botly.sendText(sender, text + users[sender].first_name, function (err, data) { + botly.sendText({id: sender, text: text + users[sender].first_name}, function (err, data) { console.log("send text cb:", err, data); }); }); @@ -141,14 +146,17 @@ botly.on('error', (ex) => { }); if (process.env.PAGE_ID) { - botly.setWelcomeScreen({pageId: process.env.PAGE_ID, message: {text: "What's upppppppppp?????!!!!"}}, function (err, body) { + botly.setGetStarted({pageId: process.env.PAGE_ID, payload: 'GET_STARTED_CLICKED'}, function (err, body) { console.log("welcome cb:", err, body); }); + botly.setPersistentMenu({pageId: process.env.PAGE_ID, buttons: [botly.createPostbackButton('reset', 'reset_me')]}, function (err, body) { + console.log("persistent menu cb:", err, body); + }) } app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: false})); -app.use('/webhook', botly.router()); +app.use('/fb', botly.router()); app.set('port', port); diff --git a/lib/Botly.js b/lib/Botly.js index 46aa54d..bedf397 100644 --- a/lib/Botly.js +++ b/lib/Botly.js @@ -92,7 +92,7 @@ Botly.prototype.getUserProfile = function (userId, callback) { }); }; -Botly.prototype.setWelcomeScreen = function (options, callback) { +Botly.prototype.setGetStarted = function (options, callback) { const PAGE_URL = `${FB_URL}${options.pageId}/thread_settings`; request.post( @@ -107,7 +107,7 @@ Botly.prototype.setWelcomeScreen = function (options, callback) { thread_state: 'new_thread', call_to_actions: [ { - message: options.message + payload: options.payload } ] } diff --git a/test/botly_test.js b/test/botly_test.js index 1d09993..e552dc8 100644 --- a/test/botly_test.js +++ b/test/botly_test.js @@ -733,16 +733,14 @@ describe('Botly Tests', function () { notificationType: Botly.CONST.NOTIFICATION_TYPE.NO_PUSH }); - botly.setWelcomeScreen({pageId: PAGE_ID, message: {text: 'hi'}}, ()=> { + botly.setGetStarted({pageId: PAGE_ID, payload: 'GET_STARTED_CLICKED'}, ()=> { }); expect(request.post.calledOnce).to.be.true; expect(request.post.args[0][0].body).to.eql({ 'call_to_actions': [ { - 'message': { - 'text': 'hi' - } + 'payload': 'GET_STARTED_CLICKED' } ], 'setting_type': 'call_to_actions',