Skip to content

Commit

Permalink
renamed setWelcomeScreen to setGetStarted since no longer supported b…
Browse files Browse the repository at this point in the history
…y facebook
  • Loading branch information
miki2826 committed Jul 4, 2016
1 parent 99efdad commit b6fd282
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
});
```
Expand Down Expand Up @@ -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.
16 changes: 12 additions & 4 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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);
});
});
Expand All @@ -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);


Expand Down
4 changes: 2 additions & 2 deletions lib/Botly.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -107,7 +107,7 @@ Botly.prototype.setWelcomeScreen = function (options, callback) {
thread_state: 'new_thread',
call_to_actions: [
{
message: options.message
payload: options.payload
}
]
}
Expand Down
6 changes: 2 additions & 4 deletions test/botly_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit b6fd282

Please sign in to comment.