messaging-api-messenger
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -6,3 +6,4 @@ 'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _extends = Object.assign || function (target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i];for (var key in source) {if (Object.prototype.hasOwnProperty.call(source, key)) {target[key] = source[key];}}}return target;};var _querystring = require('querystring');var _querystring2 = _interopRequireDefault(_querystring); | ||
var _invariant = require('invariant');var _invariant2 = _interopRequireDefault(_invariant); | ||
var _lodash = require('lodash.omit');var _lodash2 = _interopRequireDefault(_lodash);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} | ||
var _lodash = require('lodash.omit');var _lodash2 = _interopRequireDefault(_lodash); | ||
var _isPlainObject = require('is-plain-object');var _isPlainObject2 = _interopRequireDefault(_isPlainObject);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} | ||
@@ -480,2 +481,14 @@ | ||
/** | ||
@@ -794,3 +807,3 @@ * Templates | ||
if (menuItems.some(item => item.locale === 'default')) {return this.setMessengerProfile({ persistent_menu: menuItems });} // menuItems is in type Array<MenuItem> | ||
return this.setMessengerProfile({ persistent_menu: [{ locale: 'default', composer_input_disabled: composerInputDisabled, call_to_actions: menuItems }] });};this.deletePersistentMenu = () => this.deleteMessengerProfile(['persistent_menu']);this.getGreetingText = () => this.getMessengerProfile(['greeting']).then(res => res[0].greeting);this.setGreetingText = greeting => {if (typeof greeting === 'string') {return this.setMessengerProfile({ greeting: [{ locale: 'default', text: greeting }] });}return this.setMessengerProfile({ greeting });};this.deleteGreetingText = () => this.deleteMessengerProfile(['greeting']);this.getDomainWhitelist = () => this.getMessengerProfile(['whitelisted_domains']).then(res => res[0].whitelisted_domains);this.setDomainWhitelist = domains => this.setMessengerProfile({ whitelisted_domains: domains });this.deleteDomainWhitelist = () => this.deleteMessengerProfile(['whitelisted_domains']);this.getAccountLinkingURL = () => this.getMessengerProfile(['account_linking_url']).then(res => res[0]);this.setAccountLinkingURL = url => this.setMessengerProfile({ account_linking_url: url });this.deleteAccountLinkingURL = () => this.deleteMessengerProfile(['account_linking_url']);this.getPaymentSettings = () => this.getMessengerProfile(['payment_settings']).then(res => res[0]);this.setPaymentPrivacyPolicyURL = url => this.setMessengerProfile({ payment_settings: { privacy_url: url } });this.setPaymentPublicKey = key => this.setMessengerProfile({ payment_settings: { public_key: key } });this.setPaymentTestUsers = users => this.setMessengerProfile({ payment_settings: { test_users: users } });this.deletePaymentSettings = () => this.deleteMessengerProfile(['payment_settings']);this.getTargetAudience = () => this.getMessengerProfile(['target_audience']).then(res => res[0]);this.setTargetAudience = (type, whitelist = [], blacklist = []) => this.setMessengerProfile({ target_audience: { audience_type: type, countries: { whitelist, blacklist } } });this.deleteTargetAudience = () => this.deleteMessengerProfile(['target_audience']);this.getChatExtensionHomeURL = () => this.getMessengerProfile(['home_url']).then(res => res[0]);this.setChatExtensionHomeURL = (url, { webview_height_ratio, webview_share_button, in_test }) => this.setMessengerProfile({ home_url: { url, webview_height_ratio, in_test, webview_share_button } });this.deleteChatExtensionHomeURL = () => this.deleteMessengerProfile(['home_url']);this.getMessageTags = () => this._http.get(`/page_message_tags?access_token=${this._accessToken}`).then(res => res.data.data);this.sendRawBody = body => this._http.post(`/me/messages?access_token=${this._accessToken}`, body).then(res => res.data);this.send = (idOrRecipient, message, options) => {const recipient = typeof idOrRecipient === 'string' ? { id: idOrRecipient } : idOrRecipient;return this.sendRawBody(_extends({ recipient, message }, options));};this.sendFormData = (recipient, message, filedata) => {const form = new _formData2.default();const recipientObject = typeof recipient === 'string' ? { id: recipient } : recipient;form.append('recipient', JSON.stringify(recipientObject));form.append('message', JSON.stringify(message));form.append('filedata', filedata);return this._http.post(`/me/messages?access_token=${this._accessToken}`, form, { headers: form.getHeaders() }).then(res => res.data);};this.sendAttachment = (recipient, attachment, options) => this.send(recipient, { attachment }, options);this.sendAttachmentFormData = (recipient, attachment, filedata) => this.sendFormData(recipient, { attachment }, filedata);this.sendText = (recipient, text, options) => this.send(recipient, { text }, options);this.sendAudio = (recipient, audio) => {const attachment = { type: 'audio', payload: {} };if (typeof audio === 'string') {attachment.payload.url = audio;return this.sendAttachment(recipient, attachment);}return this.sendAttachmentFormData(recipient, attachment, audio);};this.sendImage = (recipient, image) => {const attachment = { type: 'image', payload: {} };if (typeof image === 'string') {attachment.payload.url = image;return this.sendAttachment(recipient, attachment);}return this.sendAttachmentFormData(recipient, attachment, image);};this.sendVideo = (recipient, video) => {const attachment = { type: 'video', payload: {} };if (typeof video === 'string') {attachment.payload.url = video;return this.sendAttachment(recipient, attachment);}return this.sendAttachmentFormData(recipient, attachment, video);};this.sendFile = (recipient, file) => {const attachment = { type: 'file', payload: {} };if (typeof file === 'string') {attachment.payload.url = file;return this.sendAttachment(recipient, attachment);}return this.sendAttachmentFormData(recipient, attachment, file);};this.sendTemplate = (recipient, payload, options) => this.sendAttachment(recipient, { type: 'template', payload }, options);this.sendButtonTemplate = (recipient, text, buttons) => this.sendTemplate(recipient, { template_type: 'button', text, buttons });this.sendGenericTemplate = (recipient, elements, options = {}) => this.sendTemplate(recipient, { template_type: 'generic', elements, image_aspect_ratio: options.image_aspect_ratio || 'horizontal' }, (0, _lodash2.default)(options, ['image_aspect_ratio']));this.sendListTemplate = (recipient, elements, buttons, options = {}) => this.sendTemplate(recipient, { template_type: 'list', elements, buttons, top_element_style: options.top_element_style || 'large' });this.sendOpenGraphTemplate = (recipient, elements) => this.sendTemplate(recipient, { template_type: 'open_graph', elements });this.sendReceiptTemplate = (recipient, attrs) => this.sendTemplate(recipient, _extends({ template_type: 'receipt' }, attrs));this.sendAirlineBoardingPassTemplate = (recipient, attrs) => this.sendTemplate(recipient, _extends({ template_type: 'airline_boardingpass' }, attrs));this.sendAirlineCheckinTemplate = (recipient, attrs) => this.sendTemplate(recipient, _extends({ template_type: 'airline_checkin' }, attrs));this.sendAirlineItineraryTemplate = (recipient, attrs) => this.sendTemplate(recipient, _extends({ template_type: 'airline_itinerary' }, attrs));this.sendAirlineFlightUpdateTemplate = (recipient, attrs) => this.sendTemplate(recipient, _extends({ template_type: 'airline_update' }, attrs));this.sendQuickReplies = (recipient, textOrAttachment, quickReplies) => {// quick_replies is limited to 11 | ||
return this.setMessengerProfile({ persistent_menu: [{ locale: 'default', composer_input_disabled: composerInputDisabled, call_to_actions: menuItems }] });};this.deletePersistentMenu = () => this.deleteMessengerProfile(['persistent_menu']);this.getGreetingText = () => this.getMessengerProfile(['greeting']).then(res => res[0].greeting);this.setGreetingText = greeting => {if (typeof greeting === 'string') {return this.setMessengerProfile({ greeting: [{ locale: 'default', text: greeting }] });}return this.setMessengerProfile({ greeting });};this.deleteGreetingText = () => this.deleteMessengerProfile(['greeting']);this.getDomainWhitelist = () => this.getMessengerProfile(['whitelisted_domains']).then(res => res[0].whitelisted_domains);this.setDomainWhitelist = domains => this.setMessengerProfile({ whitelisted_domains: domains });this.deleteDomainWhitelist = () => this.deleteMessengerProfile(['whitelisted_domains']);this.getAccountLinkingURL = () => this.getMessengerProfile(['account_linking_url']).then(res => res[0]);this.setAccountLinkingURL = url => this.setMessengerProfile({ account_linking_url: url });this.deleteAccountLinkingURL = () => this.deleteMessengerProfile(['account_linking_url']);this.getPaymentSettings = () => this.getMessengerProfile(['payment_settings']).then(res => res[0]);this.setPaymentPrivacyPolicyURL = url => this.setMessengerProfile({ payment_settings: { privacy_url: url } });this.setPaymentPublicKey = key => this.setMessengerProfile({ payment_settings: { public_key: key } });this.setPaymentTestUsers = users => this.setMessengerProfile({ payment_settings: { test_users: users } });this.deletePaymentSettings = () => this.deleteMessengerProfile(['payment_settings']);this.getTargetAudience = () => this.getMessengerProfile(['target_audience']).then(res => res[0]);this.setTargetAudience = (type, whitelist = [], blacklist = []) => this.setMessengerProfile({ target_audience: { audience_type: type, countries: { whitelist, blacklist } } });this.deleteTargetAudience = () => this.deleteMessengerProfile(['target_audience']);this.getChatExtensionHomeURL = () => this.getMessengerProfile(['home_url']).then(res => res[0]);this.setChatExtensionHomeURL = (url, { webview_height_ratio, webview_share_button, in_test }) => this.setMessengerProfile({ home_url: { url, webview_height_ratio, in_test, webview_share_button } });this.deleteChatExtensionHomeURL = () => this.deleteMessengerProfile(['home_url']);this.getMessageTags = () => this._http.get(`/page_message_tags?access_token=${this._accessToken}`).then(res => res.data.data);this.sendRawBody = body => this._http.post(`/me/messages?access_token=${this._accessToken}`, body).then(res => res.data);this.send = (idOrRecipient, message, options) => {const recipient = typeof idOrRecipient === 'string' ? { id: idOrRecipient } : idOrRecipient;return this.sendRawBody(_extends({ recipient, message }, options));};this.sendFormData = (recipient, message, filedata) => {const form = new _formData2.default();const recipientObject = typeof recipient === 'string' ? { id: recipient } : recipient;form.append('recipient', JSON.stringify(recipientObject));form.append('message', JSON.stringify(message));form.append('filedata', filedata);return this._http.post(`/me/messages?access_token=${this._accessToken}`, form, { headers: form.getHeaders() }).then(res => res.data);};this.sendAttachment = (recipient, attachment, options) => this.send(recipient, { attachment }, options);this.sendAttachmentFormData = (recipient, attachment, filedata) => this.sendFormData(recipient, { attachment }, filedata);this.sendText = (recipient, text, options) => this.send(recipient, { text }, options);this.sendAudio = (recipient, audio) => {const attachment = { type: 'audio', payload: {} };if (typeof audio === 'string') {attachment.payload.url = audio;return this.sendAttachment(recipient, attachment);} else if (audio && (0, _isPlainObject2.default)(audio)) {attachment.payload = audio;return this.sendAttachment(recipient, attachment);}return this.sendAttachmentFormData(recipient, attachment, audio);};this.sendImage = (recipient, image) => {const attachment = { type: 'image', payload: {} };if (typeof image === 'string') {attachment.payload.url = image;return this.sendAttachment(recipient, attachment);} else if (image && (0, _isPlainObject2.default)(image)) {attachment.payload = image;return this.sendAttachment(recipient, attachment);}return this.sendAttachmentFormData(recipient, attachment, image);};this.sendVideo = (recipient, video) => {const attachment = { type: 'video', payload: {} };if (typeof video === 'string') {attachment.payload.url = video;return this.sendAttachment(recipient, attachment);} else if (video && (0, _isPlainObject2.default)(video)) {attachment.payload = video;return this.sendAttachment(recipient, attachment);}return this.sendAttachmentFormData(recipient, attachment, video);};this.sendFile = (recipient, file) => {const attachment = { type: 'file', payload: {} };if (typeof file === 'string') {attachment.payload.url = file;return this.sendAttachment(recipient, attachment);} else if (file && (0, _isPlainObject2.default)(file)) {attachment.payload = file;return this.sendAttachment(recipient, attachment);}return this.sendAttachmentFormData(recipient, attachment, file);};this.sendTemplate = (recipient, payload, options) => this.sendAttachment(recipient, { type: 'template', payload }, options);this.sendButtonTemplate = (recipient, text, buttons) => this.sendTemplate(recipient, { template_type: 'button', text, buttons });this.sendGenericTemplate = (recipient, elements, options = {}) => this.sendTemplate(recipient, { template_type: 'generic', elements, image_aspect_ratio: options.image_aspect_ratio || 'horizontal' }, (0, _lodash2.default)(options, ['image_aspect_ratio']));this.sendListTemplate = (recipient, elements, buttons, options = {}) => this.sendTemplate(recipient, { template_type: 'list', elements, buttons, top_element_style: options.top_element_style || 'large' });this.sendOpenGraphTemplate = (recipient, elements) => this.sendTemplate(recipient, { template_type: 'open_graph', elements });this.sendReceiptTemplate = (recipient, attrs) => this.sendTemplate(recipient, _extends({ template_type: 'receipt' }, attrs));this.sendAirlineBoardingPassTemplate = (recipient, attrs) => this.sendTemplate(recipient, _extends({ template_type: 'airline_boardingpass' }, attrs));this.sendAirlineCheckinTemplate = (recipient, attrs) => this.sendTemplate(recipient, _extends({ template_type: 'airline_checkin' }, attrs));this.sendAirlineItineraryTemplate = (recipient, attrs) => this.sendTemplate(recipient, _extends({ template_type: 'airline_itinerary' }, attrs));this.sendAirlineFlightUpdateTemplate = (recipient, attrs) => this.sendTemplate(recipient, _extends({ template_type: 'airline_update' }, attrs));this.sendQuickReplies = (recipient, textOrAttachment, quickReplies) => {// quick_replies is limited to 11 | ||
(0, _invariant2.default)(Array.isArray(quickReplies) && quickReplies.length <= 11, 'quickReplies is an array and limited to 11');quickReplies.forEach(quickReply => {if (quickReply.content_type === 'text') {// title has a 20 character limit, after that it gets truncated | ||
@@ -797,0 +810,0 @@ (0, _invariant2.default)(quickReply.title.trim().length <= 20, 'title of quickReply has a 20 character limit, after that it gets truncated'); // payload has a 1000 character limit |
{ | ||
"name": "messaging-api-messenger", | ||
"description": "Messaging API client for Messenger", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"engines": { | ||
@@ -24,4 +24,5 @@ "node": ">=6" | ||
"invariant": "^2.2.2", | ||
"is-plain-object": "^2.0.4", | ||
"lodash.omit": "^4.5.0" | ||
} | ||
} |
@@ -198,3 +198,3 @@ # messaging-api-messenger | ||
Type: `String | Buffer | ReadStream` | ||
Type: `String | Buffer | ReadStream | AttachmentPayload` | ||
@@ -207,2 +207,8 @@ Send audio using url string: | ||
using `AttachmentPayload` to send cached attachment: | ||
```js | ||
client.sendAudio(USER_ID, { attachment_id: '55688' }); | ||
``` | ||
or using `ReadStream` created from local file: | ||
@@ -232,3 +238,3 @@ | ||
Type: `String | Buffer | ReadStream` | ||
Type: `String | Buffer | ReadStream | AttachmentPayload` | ||
@@ -241,2 +247,8 @@ Send image using url string: | ||
using `AttachmentPayload` to send cached attachment: | ||
```js | ||
client.sendImage(USER_ID, { attachment_id: '55688' }); | ||
``` | ||
or using `ReadStream` created from local file: | ||
@@ -266,3 +278,3 @@ | ||
Type: `String | Buffer | ReadStream` | ||
Type: `String | Buffer | ReadStream | AttachmentPayload` | ||
@@ -275,2 +287,8 @@ Send video using url string: | ||
using `AttachmentPayload` to send cached attachment: | ||
```js | ||
client.sendVideo(USER_ID, { attachment_id: '55688' }); | ||
``` | ||
or using `ReadStream` created from local file: | ||
@@ -300,3 +318,3 @@ | ||
Type: `String | Buffer | ReadStream` | ||
Type: `String | Buffer | ReadStream | AttachmentPayload` | ||
@@ -309,2 +327,8 @@ Send file using url string: | ||
using `AttachmentPayload` to send cached attachment: | ||
```js | ||
client.sendFile(USER_ID, { attachment_id: '55688' }); | ||
``` | ||
or using `ReadStream` created from local file: | ||
@@ -311,0 +335,0 @@ |
@@ -7,2 +7,3 @@ import querystring from 'querystring'; | ||
import omit from 'lodash.omit'; | ||
import isPlainObject from 'is-plain-object'; | ||
@@ -414,3 +415,3 @@ import type { | ||
recipient: UserID | Recipient, | ||
audio: string | FileData | ||
audio: string | FileData | AttachmentPayload | ||
): Promise<SendMessageSucessResponse> => { | ||
@@ -425,2 +426,5 @@ const attachment = { | ||
return this.sendAttachment(recipient, attachment); | ||
} else if (audio && isPlainObject(audio)) { | ||
attachment.payload = audio; | ||
return this.sendAttachment(recipient, attachment); | ||
} | ||
@@ -433,3 +437,3 @@ | ||
recipient: UserID | Recipient, | ||
image: string | FileData | ||
image: string | FileData | AttachmentPayload | ||
): Promise<SendMessageSucessResponse> => { | ||
@@ -444,2 +448,5 @@ const attachment = { | ||
return this.sendAttachment(recipient, attachment); | ||
} else if (image && isPlainObject(image)) { | ||
attachment.payload = image; | ||
return this.sendAttachment(recipient, attachment); | ||
} | ||
@@ -452,3 +459,3 @@ | ||
recipient: UserID | Recipient, | ||
video: string | FileData | ||
video: string | FileData | AttachmentPayload | ||
): Promise<SendMessageSucessResponse> => { | ||
@@ -463,2 +470,5 @@ const attachment = { | ||
return this.sendAttachment(recipient, attachment); | ||
} else if (video && isPlainObject(video)) { | ||
attachment.payload = video; | ||
return this.sendAttachment(recipient, attachment); | ||
} | ||
@@ -471,3 +481,3 @@ | ||
recipient: UserID | Recipient, | ||
file: string | FileData | ||
file: string | FileData | AttachmentPayload | ||
): Promise<SendMessageSucessResponse> => { | ||
@@ -482,2 +492,5 @@ const attachment = { | ||
return this.sendAttachment(recipient, attachment); | ||
} else if (file && isPlainObject(file)) { | ||
attachment.payload = file; | ||
return this.sendAttachment(recipient, attachment); | ||
} | ||
@@ -484,0 +497,0 @@ |
@@ -19,2 +19,4 @@ /* @flow */ | ||
url?: string, | ||
is_reusable?: boolean, | ||
attachment_id?: string, | ||
}; | ||
@@ -21,0 +23,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
216507
4680
2110
5
+ Addedis-plain-object@^2.0.4
+ Addedis-plain-object@2.0.4(transitive)
+ Addedisobject@3.0.1(transitive)