From 70a11fa7a8a11cc45e8391c534dff7e604516152 Mon Sep 17 00:00:00 2001 From: Dom Webber Date: Thu, 30 Nov 2023 15:59:49 +0000 Subject: [PATCH] refactor: correct affected types bnased on OldMessageTypes' removal --- src/CloudMessageAPI/index.ts | 9 +++++---- .../EventNotificationMessage.ts | 10 ++-------- .../EventNotificationStatus.ts | 2 +- src/EventNotification/index.ts | 15 ++++++++------ .../OutgoingMessage/CloudOutgoingMessage.ts | 20 ++++++++++++++++++- .../OutgoingMessage/HostedOutgoingMessage.ts | 19 ++++++++++++++++++ 6 files changed, 55 insertions(+), 20 deletions(-) diff --git a/src/CloudMessageAPI/index.ts b/src/CloudMessageAPI/index.ts index 3fbfce6..51daffc 100644 --- a/src/CloudMessageAPI/index.ts +++ b/src/CloudMessageAPI/index.ts @@ -17,9 +17,10 @@ import CloudOutgoingMessageStatus from "../Message/MessageStatus/CloudOutgoingMe import CloudOutgoingMessageTemplate from "../Message/MessageTemplate/CloudOutgoingMessageTemplate"; import CloudOutgoingMessageText from "../Message/MessageText/CloudOutgoingMessageText"; import OutgoingMessageType from "../Message/MessageType/OutgoingMessageType"; -import CloudOutgoingMessage from "../Message/OutgoingMessage/CloudOutgoingMessage"; +import CloudOutgoingMessage, { + CloudOutgoingMessageResponse, +} from "../Message/OutgoingMessage/CloudOutgoingMessage"; import CloudOutgoingStatusMessage from "../Message/StatusMessage/CloudOutgoingStatusMessage"; -import MessageResponseType from "../OldMessageType/MessageResponseType"; type CreateMessagePayload = | CloudOutgoingMessageMedia @@ -66,7 +67,7 @@ export default class CloudMessageAPI extends AbstractAPI { ...payload, }; - return GraphRequest.create({ + return GraphRequest.create({ ...requestProps, endpoint: this.getEndpoint(), method: "POST", @@ -99,7 +100,7 @@ export default class CloudMessageAPI extends AbstractAPI { if (replyMessageId) body["context"] = { message_id: replyMessageId }; - return GraphRequest.create({ + return GraphRequest.create({ ...requestProps, endpoint: this.getEndpoint(), method: "POST", diff --git a/src/EventNotification/EventNotificationMessage.ts b/src/EventNotification/EventNotificationMessage.ts index fcdd919..e4e44c5 100644 --- a/src/EventNotification/EventNotificationMessage.ts +++ b/src/EventNotification/EventNotificationMessage.ts @@ -11,15 +11,9 @@ import CloudIncomingMessageContext from "../Message/MessageContext/CloudIncoming import CloudIncomingMessageIdentity from "../Message/MessageIdentity/CloudIncomingMessageIdentity"; import CloudIncomingMessageReferral from "../Message/MessageReferral/CloudIncomingMessageReferral"; import CloudIncomingMessageSystem from "../Message/MessageSystem/CloudIncomingMessageSystem"; -import MessageTypesEnum from "../OldMessageType/MessageTypesEnum"; +import IncomingMessageType from "../Message/MessageType/IncomingMessageType"; -export type EventNotificationMessageType = - | MessageTypesEnum - | "button" - | "system" - | "unknown"; - -type EventNotificationMessage = { +type EventNotificationMessage = { /** * The type of message that has been received by the business that has * subscribed to Webhooks. diff --git a/src/EventNotification/EventNotificationStatus.ts b/src/EventNotification/EventNotificationStatus.ts index 9a2042a..bb8f21f 100644 --- a/src/EventNotification/EventNotificationStatus.ts +++ b/src/EventNotification/EventNotificationStatus.ts @@ -7,7 +7,7 @@ * @see https://greatdetail.com */ import { WhatsAppAccountID } from "../API/AbstractAPI"; -import { MessageID } from "../OldMessageType/MessageType"; +import { MessageID } from "../Message"; export enum EventNotificationStatusReason { /** diff --git a/src/EventNotification/index.ts b/src/EventNotification/index.ts index e88ce20..cc17fc3 100644 --- a/src/EventNotification/index.ts +++ b/src/EventNotification/index.ts @@ -8,10 +8,6 @@ */ import { WhatsAppAccountID } from "../API/AbstractAPI"; import { EventNotificationError } from "../Error"; -import { - RequestBodyType, - WhatsAppMessageType, -} from "../OldMessageType/MessageType"; import EventNotificationStatus from "./EventNotificationStatus"; export type WhatsAppPhoneNumberID = string; @@ -28,7 +24,14 @@ export type EventNotificationContact = { }; }; -export type EventNotificationChangeValue = WhatsAppMessageType & { +export type EventNotificationChangeValue = { + /** + * Messaging service used for the request. Use "whatsapp". + * + * @default 'whatsapp' + */ + messaging_product: "whatsapp"; + metadata: EventNotificationMetadata; statuses?: EventNotificationStatus[]; @@ -55,7 +58,7 @@ export type EventNotificationEntry = { changes: EventNotificationChange[]; }; -export type EventNotificationType = RequestBodyType & { +export type EventNotificationType = { object: string; entry: EventNotificationEntry[]; }; diff --git a/src/Message/OutgoingMessage/CloudOutgoingMessage.ts b/src/Message/OutgoingMessage/CloudOutgoingMessage.ts index cdee32b..e4a488d 100644 --- a/src/Message/OutgoingMessage/CloudOutgoingMessage.ts +++ b/src/Message/OutgoingMessage/CloudOutgoingMessage.ts @@ -7,9 +7,27 @@ * @see https://greatdetail.com */ import OutgoingMessage from "."; -import { MessageID } from ".."; +import { AccountID, MessageID } from ".."; import OutgoingMessageType from "../MessageType/OutgoingMessageType"; +export interface CloudOutgoingMessageResponse { + /** + * Messaging service used for the request. Use "whatsapp". + * + * @default 'whatsapp' + */ + messaging_product: "whatsapp"; + + // TODO: Reuse this + contacts: { + input: string; + wa_id: AccountID; + }[]; + messages: { + id: MessageID; + }[]; +} + export interface CloudOutgoingMessageContext { /** * The ID of a previous message you are replying to. diff --git a/src/Message/OutgoingMessage/HostedOutgoingMessage.ts b/src/Message/OutgoingMessage/HostedOutgoingMessage.ts index a445656..5879523 100644 --- a/src/Message/OutgoingMessage/HostedOutgoingMessage.ts +++ b/src/Message/OutgoingMessage/HostedOutgoingMessage.ts @@ -7,8 +7,27 @@ * @see https://greatdetail.com */ import OutgoingMessage from "."; +import { AccountID, MessageID } from ".."; import OutgoingMessageType from "../MessageType/OutgoingMessageType"; +export interface HostedOutgoingMessageResponse { + /** + * Messaging service used for the request. Use "whatsapp". + * + * @default 'whatsapp' + */ + messaging_product: "whatsapp"; + + // TODO: Reuse this + contacts: { + input: string; + wa_id: AccountID; + }[]; + messages: { + id: MessageID; + }[]; +} + export interface HostedOutgoingMessageHsm { /** * The namespace to be used. Beginning with v2.2.7, if the namespace does not