@great-detail/whatsapp
Advanced tools
Comparing version 2.4.0 to 3.0.0
@@ -25,2 +25,8 @@ /** | ||
import { TextObjectMessageType } from "../Message/TextObjectMessageType"; | ||
type CreateMessagePayloadType<C extends ComponentTypesEnum> = AudioObjectMediaMessageType | [ContactsObjectMessageType] | DocumentObjectMediaMessageType | ImageObjectMediaMessageType | InteractiveObjectMessageType | LocationObjectMessageType | TemplateObjectMessageType<C> | StickerObjectMediaMessageType | TextObjectMessageType | VideoObjectMediaMessageType; | ||
type CreateMessageOptionsType = { | ||
toNumber: string; | ||
replyMessageId?: string; | ||
requestProps?: GraphRequestProps; | ||
}; | ||
/** | ||
@@ -34,4 +40,28 @@ * WhatsApp Message API. | ||
protected getEndpoint(): string; | ||
createStatusRead(payload: StatusObjectMessageType, requestProps?: GraphRequestProps): GraphRequest<unknown>; | ||
createMessage<T extends MessageTypesEnum, C extends ComponentTypesEnum>(type: T, payload: AudioObjectMediaMessageType | [ContactsObjectMessageType] | DocumentObjectMediaMessageType | ImageObjectMediaMessageType | InteractiveObjectMessageType | LocationObjectMessageType | TemplateObjectMessageType<C> | StickerObjectMediaMessageType | TextObjectMessageType | VideoObjectMediaMessageType, toNumber: string, replyMessageId?: string, requestProps?: GraphRequestProps): GraphRequest<MessageResponseType>; | ||
/** | ||
* Create Status Message. | ||
* | ||
* @since 2.0.0 | ||
* @author Dom Webber <dom.webber@hotmail.com> | ||
*/ | ||
createStatus(payload: StatusObjectMessageType, requestProps?: GraphRequestProps): GraphRequest<MessageResponseType>; | ||
/** | ||
* Create Message. | ||
* | ||
* @since 2.0.0 | ||
* @author Dom Webber <dom.webber@hotmail.com> | ||
*/ | ||
createMessage<T extends MessageTypesEnum, C extends ComponentTypesEnum>(type: T, payload: CreateMessagePayloadType<C>, { toNumber, replyMessageId, requestProps }: CreateMessageOptionsType): GraphRequest<MessageResponseType>; | ||
protected _shorthandAlias<T extends MessageTypesEnum, C extends ComponentTypesEnum, P extends CreateMessagePayloadType<C>>(type: T): (payload: P, options: CreateMessageOptionsType) => GraphRequest<MessageResponseType>; | ||
audio: (payload: CreateMessagePayloadType<ComponentTypesEnum>, options: CreateMessageOptionsType) => GraphRequest<MessageResponseType>; | ||
contacts: (payload: CreateMessagePayloadType<ComponentTypesEnum>, options: CreateMessageOptionsType) => GraphRequest<MessageResponseType>; | ||
document: (payload: CreateMessagePayloadType<ComponentTypesEnum>, options: CreateMessageOptionsType) => GraphRequest<MessageResponseType>; | ||
image: (payload: CreateMessagePayloadType<ComponentTypesEnum>, options: CreateMessageOptionsType) => GraphRequest<MessageResponseType>; | ||
interactive: (payload: CreateMessagePayloadType<ComponentTypesEnum>, options: CreateMessageOptionsType) => GraphRequest<MessageResponseType>; | ||
location: (payload: CreateMessagePayloadType<ComponentTypesEnum>, options: CreateMessageOptionsType) => GraphRequest<MessageResponseType>; | ||
sticker: (payload: CreateMessagePayloadType<ComponentTypesEnum>, options: CreateMessageOptionsType) => GraphRequest<MessageResponseType>; | ||
template: (payload: CreateMessagePayloadType<ComponentTypesEnum>, options: CreateMessageOptionsType) => GraphRequest<MessageResponseType>; | ||
text: (payload: CreateMessagePayloadType<ComponentTypesEnum>, options: CreateMessageOptionsType) => GraphRequest<MessageResponseType>; | ||
video: (payload: CreateMessagePayloadType<ComponentTypesEnum>, options: CreateMessageOptionsType) => GraphRequest<MessageResponseType>; | ||
} | ||
export {}; |
@@ -13,7 +13,21 @@ "use strict"; | ||
const GraphRequest_1 = __importDefault(require("../GraphRequest")); | ||
const MessageTypesEnum_1 = __importDefault(require("../Message/MessageTypesEnum")); | ||
class MessageAPI extends AbstractAPI_1.default { | ||
constructor() { | ||
super(...arguments); | ||
this.audio = this._shorthandAlias(MessageTypesEnum_1.default.Audio); | ||
this.contacts = this._shorthandAlias(MessageTypesEnum_1.default.Contacts); | ||
this.document = this._shorthandAlias(MessageTypesEnum_1.default.Document); | ||
this.image = this._shorthandAlias(MessageTypesEnum_1.default.Image); | ||
this.interactive = this._shorthandAlias(MessageTypesEnum_1.default.Interactive); | ||
this.location = this._shorthandAlias(MessageTypesEnum_1.default.Location); | ||
this.sticker = this._shorthandAlias(MessageTypesEnum_1.default.Sticker); | ||
this.template = this._shorthandAlias(MessageTypesEnum_1.default.Template); | ||
this.text = this._shorthandAlias(MessageTypesEnum_1.default.Text); | ||
this.video = this._shorthandAlias(MessageTypesEnum_1.default.Video); | ||
} | ||
getEndpoint() { | ||
return this.joinEndpoints(this.getParentEndpoint(), this.businessId, "messages"); | ||
} | ||
createStatusRead(payload, requestProps = {}) { | ||
createStatus(payload, requestProps = {}) { | ||
const body = { | ||
@@ -34,3 +48,7 @@ messaging_product: "whatsapp", | ||
} | ||
createMessage(type, payload, toNumber, replyMessageId, requestProps = {}) { | ||
createMessage(type, payload, { | ||
toNumber, | ||
replyMessageId, | ||
requestProps = {} | ||
}) { | ||
const body = { | ||
@@ -57,3 +75,9 @@ messaging_product: "whatsapp", | ||
} | ||
_shorthandAlias(type) { | ||
const shorthandAliasFunction = function (payload, options) { | ||
return this.createMessage(type, payload, options); | ||
}; | ||
return shorthandAliasFunction.bind(this); | ||
} | ||
} | ||
exports.default = MessageAPI; |
{ | ||
"name": "@great-detail/whatsapp", | ||
"version": "2.4.0", | ||
"version": "3.0.0", | ||
"license": "SEE LICENSE IN LICENSE FILE", | ||
@@ -5,0 +5,0 @@ "description": "SDK for interfacing with WhatsApp Business Platform in Typescript or Node.js using the Cloud API, hosted by Meta.", |
@@ -29,2 +29,20 @@ /** | ||
type CreateMessagePayloadType<C extends ComponentTypesEnum> = | ||
| AudioObjectMediaMessageType | ||
| [ContactsObjectMessageType] | ||
| DocumentObjectMediaMessageType | ||
| ImageObjectMediaMessageType | ||
| InteractiveObjectMessageType | ||
| LocationObjectMessageType | ||
| TemplateObjectMessageType<C> | ||
| StickerObjectMediaMessageType | ||
| TextObjectMessageType | ||
| VideoObjectMediaMessageType; | ||
type CreateMessageOptionsType = { | ||
toNumber: string; | ||
replyMessageId?: string; | ||
requestProps?: GraphRequestProps; | ||
}; | ||
/** | ||
@@ -45,3 +63,9 @@ * WhatsApp Message API. | ||
public createStatusRead( | ||
/** | ||
* Create Status Message. | ||
* | ||
* @since 2.0.0 | ||
* @author Dom Webber <dom.webber@hotmail.com> | ||
*/ | ||
public createStatus( | ||
payload: StatusObjectMessageType, | ||
@@ -55,3 +79,3 @@ requestProps: GraphRequestProps = {}, | ||
return new GraphRequest({ | ||
return new GraphRequest<MessageResponseType>({ | ||
...requestProps, | ||
@@ -68,2 +92,8 @@ endpoint: this.getEndpoint(), | ||
/** | ||
* Create Message. | ||
* | ||
* @since 2.0.0 | ||
* @author Dom Webber <dom.webber@hotmail.com> | ||
*/ | ||
public createMessage< | ||
@@ -74,16 +104,4 @@ T extends MessageTypesEnum, | ||
type: T, | ||
payload: | ||
| AudioObjectMediaMessageType | ||
| [ContactsObjectMessageType] | ||
| DocumentObjectMediaMessageType | ||
| ImageObjectMediaMessageType | ||
| InteractiveObjectMessageType | ||
| LocationObjectMessageType | ||
| TemplateObjectMessageType<C> | ||
| StickerObjectMediaMessageType | ||
| TextObjectMessageType | ||
| VideoObjectMediaMessageType, | ||
toNumber: string, | ||
replyMessageId?: string, | ||
requestProps: GraphRequestProps = {}, | ||
payload: CreateMessagePayloadType<C>, | ||
{ toNumber, replyMessageId, requestProps = {} }: CreateMessageOptionsType, | ||
) { | ||
@@ -111,2 +129,29 @@ const body: MessageType<T> = { | ||
} | ||
protected _shorthandAlias< | ||
T extends MessageTypesEnum, | ||
C extends ComponentTypesEnum, | ||
P extends CreateMessagePayloadType<C>, | ||
>(type: T) { | ||
const shorthandAliasFunction = function ( | ||
this: MessageAPI, | ||
payload: P, | ||
options: CreateMessageOptionsType, | ||
) { | ||
return this.createMessage(type, payload, options); | ||
}; | ||
return shorthandAliasFunction.bind(this); | ||
} | ||
public audio = this._shorthandAlias(MessageTypesEnum.Audio); | ||
public contacts = this._shorthandAlias(MessageTypesEnum.Contacts); | ||
public document = this._shorthandAlias(MessageTypesEnum.Document); | ||
public image = this._shorthandAlias(MessageTypesEnum.Image); | ||
public interactive = this._shorthandAlias(MessageTypesEnum.Interactive); | ||
public location = this._shorthandAlias(MessageTypesEnum.Location); | ||
public sticker = this._shorthandAlias(MessageTypesEnum.Sticker); | ||
public template = this._shorthandAlias(MessageTypesEnum.Template); | ||
public text = this._shorthandAlias(MessageTypesEnum.Text); | ||
public video = this._shorthandAlias(MessageTypesEnum.Video); | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
125609
3291