facebook-send-api
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -72,2 +72,3 @@ import * as Promise from 'bluebird'; | ||
title(title: string): this; | ||
text(text: string): this; | ||
subtitle(sutitle: string): this; | ||
@@ -80,2 +81,3 @@ postbackButton(text: string, postback: string): this; | ||
export declare class FBElement extends FBMessage { | ||
constructor(platform?: FBPlatform); | ||
create(): MessengerItem; | ||
@@ -87,3 +89,2 @@ } | ||
export declare class FBGenericMessage extends FBMessage { | ||
text(text: string): this; | ||
send(): Promise<MessengerResponse>; | ||
@@ -103,4 +104,6 @@ } | ||
protected sendInDevelopment: boolean; | ||
protected validateLimits: boolean; | ||
constructor(token: string); | ||
turnOnSendingInDevelopment(state?: boolean): this; | ||
turnOnValidation(state?: boolean): this; | ||
private sendToFB(payload, path); | ||
@@ -107,0 +110,0 @@ sendMessageToFB(id: string, message: MessengerMessage): Promise<MessengerResponse>; |
@@ -22,2 +22,6 @@ "use strict"; | ||
}; | ||
FBMessage.prototype.text = function (text) { | ||
this.messageTitle = text; | ||
return this; | ||
}; | ||
FBMessage.prototype.subtitle = function (sutitle) { | ||
@@ -53,4 +57,6 @@ this.messageSubTitle = sutitle; | ||
__extends(FBElement, _super); | ||
function FBElement() { | ||
_super.apply(this, arguments); | ||
function FBElement(platform) { | ||
if (platform === void 0) { platform = new FBPlatform(null); } | ||
_super.call(this, platform, null); | ||
return this; | ||
} | ||
@@ -88,6 +94,2 @@ FBElement.prototype.create = function () { | ||
} | ||
FBGenericMessage.prototype.text = function (text) { | ||
this.messageTitle = text; | ||
return this; | ||
}; | ||
FBGenericMessage.prototype.send = function () { | ||
@@ -141,2 +143,3 @@ return this.platform.sendGenericMessage(this.id, this.elements); | ||
this.sendInDevelopment = false; | ||
this.validateLimits = false; | ||
} | ||
@@ -148,2 +151,7 @@ FBPlatform.prototype.turnOnSendingInDevelopment = function (state) { | ||
}; | ||
FBPlatform.prototype.turnOnValidation = function (state) { | ||
if (state === void 0) { state = true; } | ||
this.validateLimits = state; | ||
return this; | ||
}; | ||
FBPlatform.prototype.sendToFB = function (payload, path) { | ||
@@ -158,3 +166,3 @@ if (process.env.NODE_ENV === 'development' && this.sendInDevelopment === false) { | ||
var requstPayload = { | ||
url: FBGraphURL + "/messages", | ||
url: "" + FBGraphURL + path, | ||
qs: { access_token: this.token }, | ||
@@ -185,4 +193,4 @@ method: 'POST', | ||
var maxElements = 10; | ||
if (elements.length > maxElements) { | ||
throw new Error('Too many elements'); | ||
if (elements.length > maxElements && this.validateLimits) { | ||
throw new Error("Sending too many elements, max is " + maxElements + ", tried sending " + elements.length); | ||
} | ||
@@ -217,4 +225,4 @@ //title has length max of 80 | ||
var maxButtons = 3; | ||
if (theButtons.length > maxButtons) { | ||
throw new Error('Too many buttons'); | ||
if (theButtons.length > maxButtons && this.validateLimits) { | ||
throw new Error("Sending too many buttons, max is " + maxButtons + ", tried sending " + theButtons.length); | ||
} | ||
@@ -246,8 +254,9 @@ var messageData = { | ||
FBPlatform.prototype.sendQuickReplies = function (id, text, quickReplies) { | ||
if (quickReplies.length > 10) { | ||
throw new Error('Quick replies limited to 10'); | ||
var maxQuickReplies = 10; | ||
if (quickReplies.length > maxQuickReplies && this.validateLimits) { | ||
throw new Error("Quick replies limited to " + maxQuickReplies + ", tried sending " + quickReplies.length); | ||
} | ||
var messageData = { | ||
text: text, | ||
quick_replies: quickReplies, | ||
quick_replies: quickReplies.slice(0, maxQuickReplies), | ||
}; | ||
@@ -254,0 +263,0 @@ return this.sendMessageToFB(id, messageData); |
{ | ||
"name": "facebook-send-api", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Promise based module to speak to the facebook send api for the messenger platform", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -112,2 +112,7 @@ import * as Promise from 'bluebird'; | ||
public text(text: string) { | ||
this.messageTitle = text; | ||
return this; | ||
} | ||
public subtitle(sutitle: string) { | ||
@@ -145,2 +150,6 @@ this.messageSubTitle = sutitle; | ||
export class FBElement extends FBMessage { | ||
constructor(platform: FBPlatform = new FBPlatform(null)) { | ||
super(platform, null); | ||
return this; | ||
} | ||
public create():MessengerItem { | ||
@@ -163,6 +172,2 @@ let element:any = {}; | ||
export class FBGenericMessage extends FBMessage { | ||
public text(text: string) { | ||
this.messageTitle = text; | ||
return this; | ||
} | ||
public send() { | ||
@@ -198,5 +203,7 @@ return this.platform.sendGenericMessage(this.id, this.elements); | ||
protected sendInDevelopment: boolean; | ||
protected validateLimits: boolean; | ||
constructor(token: string) { | ||
this.token = token; | ||
this.sendInDevelopment = false; | ||
this.validateLimits = false; | ||
} | ||
@@ -209,2 +216,7 @@ | ||
public turnOnValidation(state: boolean = true) { | ||
this.validateLimits = state; | ||
return this; | ||
} | ||
private sendToFB(payload: MessengerPayload | MessengerSettings, path: string): Promise<MessengerResponse> { | ||
@@ -220,3 +232,3 @@ if (process.env.NODE_ENV === 'development' && this.sendInDevelopment === false) { | ||
const requstPayload = { | ||
url: `${FBGraphURL}/messages`, | ||
url: `${FBGraphURL}${path}`, | ||
qs: { access_token: this.token }, | ||
@@ -252,4 +264,4 @@ method: 'POST', | ||
const maxElements = 10; | ||
if (elements.length > maxElements) { | ||
throw new Error('Too many elements'); | ||
if (elements.length > maxElements && this.validateLimits) { | ||
throw new Error(`Sending too many elements, max is ${maxElements}, tried sending ${elements.length}`); | ||
} | ||
@@ -289,4 +301,4 @@ | ||
const maxButtons = 3; | ||
if (theButtons.length > maxButtons) { | ||
throw new Error('Too many buttons'); | ||
if (theButtons.length > maxButtons && this.validateLimits) { | ||
throw new Error(`Sending too many buttons, max is ${maxButtons}, tried sending ${theButtons.length}`); | ||
} | ||
@@ -324,4 +336,5 @@ | ||
public sendQuickReplies(id: string, text: string, quickReplies: Array<MessengerQuickReply>) { | ||
if (quickReplies.length > 10) { | ||
throw new Error('Quick replies limited to 10'); | ||
const maxQuickReplies = 10; | ||
if (quickReplies.length > maxQuickReplies && this.validateLimits) { | ||
throw new Error(`Quick replies limited to ${maxQuickReplies}, tried sending ${quickReplies.length}`); | ||
} | ||
@@ -331,3 +344,3 @@ | ||
text, | ||
quick_replies: quickReplies, | ||
quick_replies: quickReplies.slice(0, maxQuickReplies), | ||
} | ||
@@ -334,0 +347,0 @@ |
Sorry, the diff of this file is not supported yet
196529
4445