Comparing version 0.2.3 to 0.3.0
@@ -13,5 +13,5 @@ var request = require('request'); | ||
json: { | ||
recipient: {id:recipient}, | ||
message: message, | ||
notification_type: config.notification_type | ||
recipient: {id:recipient}, | ||
message: message, | ||
notification_type: config.notification_type | ||
} | ||
@@ -223,2 +223,60 @@ }; | ||
function setWelcomeMessage(message, cb) { | ||
var data = { | ||
"setting_type":"call_to_actions", | ||
"thread_state":"new_thread", | ||
"call_to_actions":[ | ||
{ | ||
"message":message | ||
} | ||
] | ||
}; | ||
var requestBody = { | ||
url: 'https://graph.facebook.com/v2.6/'+config.page_id+'/thread_settings', | ||
qs: {access_token:config.access_token}, | ||
method: 'POST', | ||
json: data | ||
}; | ||
request(requestBody, function(err, resp, body) { | ||
if(!err && body.result == "Successfully added new_thread's CTAs") { | ||
//All good | ||
cb(undefined); | ||
} else if (!err && body.result != "Successfully added new_thread's CTAs") { | ||
cb("not_set"); | ||
} else { | ||
cb(err); | ||
} | ||
}); | ||
} | ||
//Set welcome message | ||
module.setTextWelcomeMessage = function(text, cb) { | ||
var message = { | ||
"text":text | ||
}; | ||
setWelcomeMessage(message, function(err) { | ||
cb(err); | ||
}); | ||
}; | ||
module.setGenericWelcomeMessage = function(bubbles, cb) { | ||
var message = { | ||
"attachment": { | ||
"type": "template", | ||
"payload": { | ||
"template_type":"generic", | ||
"elements": bubbles | ||
} | ||
} | ||
}; | ||
setWelcomeMessage(message, function(err) { | ||
cb(err); | ||
}); | ||
}; | ||
//Verify middleware | ||
@@ -225,0 +283,0 @@ module.verify = function(error) { |
{ | ||
"name": "fb-msngr", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"description": "A node module for building messenger bots", | ||
@@ -5,0 +5,0 @@ "main": "fb-msngr.js", |
@@ -20,3 +20,4 @@ # fb-msngr | ||
notification_type: <notification_type>, | ||
verify_token: <verify_token> | ||
verify_token: <verify_token>, | ||
page_id: <page_id> | ||
}); | ||
@@ -48,3 +49,3 @@ | ||
###### `require('fb-msngr')(config)` | ||
Upon including the module you must pass in a config object of the form below. `access_token` is your page access token and `verify_token` is the token you enter when you setup your webhook, both of these are created in the Facebook Developers console. `notification_type` is the type of notification your bot will create. This can be either `REGULAR`, `SILENT_PUSH` or `NO_PUSH`. | ||
Upon including the module you must pass in a config object of the form below. `access_token` is your page access token and `verify_token` is the token you enter when you setup your webhook, both of these are created in the Facebook Developers console. `notification_type` is the type of notification your bot will create. This can be either `REGULAR`, `SILENT_PUSH` or `NO_PUSH`. Finally, `page_id` is the id of the page you're using for your bot. | ||
```javascript | ||
@@ -54,3 +55,4 @@ var fbMsngr = require('fb-msngr')({ | ||
notification_type: <notification_type>, | ||
verify_token: <verify_token> | ||
verify_token: <verify_token>, | ||
page_id: <page_id> | ||
}); | ||
@@ -151,3 +153,3 @@ ``` | ||
###### `buildBubble` | ||
###### `fbMsngr.buildBubble` | ||
Builds a bubble object for use in `sendGenericTemplateMessage`. `title` is the bubble title, `url` is the URL that the bubble will link to, which is optional and can just be an empty string. `image_url` is the image sent along with the bubble, which is also optional. `subtitle` is the optional bubble subtitle. `buttons` is an array of buttons, that can be built with the below functions. | ||
@@ -158,3 +160,3 @@ ```javascript | ||
###### `buildURLButton` | ||
###### `fbMsngr.buildURLButton` | ||
Builds a button that links out to a URL. `title` is the title and the `url` is the URL that will be linked out to. | ||
@@ -165,3 +167,3 @@ ```javascript | ||
###### `buildPostbackButton` | ||
###### `fbMsngr.buildPostbackButton` | ||
Builds a button that sends a postback to your server. `title` is the title, while `payload` is the postback object that will be sent back to your server. | ||
@@ -172,2 +174,18 @@ ```javascript | ||
###### `fbMsngr.setTextWelcomeMessage` | ||
Sets your bots welcome message to a simple text message. The `text` parameter is the text, and the second parameter is a callback function which will hold an error if one has been thrown. | ||
```javascript | ||
fbMsngr.setTextWelcomeMessage(text, function(err) { | ||
}); | ||
``` | ||
###### `fbMsngr.setGenericWelcomeMessage` | ||
Sets the welcome message to a slightly more complex message. `bubbles` is an array of bubbles built with `buildBubble()`, while the second parameter is a callback identical to the one above. | ||
```javascript | ||
fbMsngr.setGenericWelcomeMessage(bubbles, function(err) { | ||
}); | ||
``` | ||
#### To-do List | ||
@@ -174,0 +192,0 @@ --- |
14153
261
187