Skip to content

Commit

Permalink
refactor: correct affected types bnased on OldMessageTypes' removal
Browse files Browse the repository at this point in the history
  • Loading branch information
domwebber committed Nov 30, 2023
1 parent e86f705 commit 70a11fa
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 20 deletions.
9 changes: 5 additions & 4 deletions src/CloudMessageAPI/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,7 +67,7 @@ export default class CloudMessageAPI extends AbstractAPI {
...payload,
};

return GraphRequest.create<MessageResponseType>({
return GraphRequest.create<CloudOutgoingMessageResponse>({
...requestProps,
endpoint: this.getEndpoint(),
method: "POST",
Expand Down Expand Up @@ -99,7 +100,7 @@ export default class CloudMessageAPI extends AbstractAPI {

if (replyMessageId) body["context"] = { message_id: replyMessageId };

return GraphRequest.create<MessageResponseType>({
return GraphRequest.create<CloudOutgoingMessageResponse>({
...requestProps,
endpoint: this.getEndpoint(),
method: "POST",
Expand Down
10 changes: 2 additions & 8 deletions src/EventNotification/EventNotificationMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends EventNotificationMessageType> = {
type EventNotificationMessage<T extends IncomingMessageType> = {
/**
* The type of message that has been received by the business that has
* subscribed to Webhooks.
Expand Down
2 changes: 1 addition & 1 deletion src/EventNotification/EventNotificationStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down
15 changes: 9 additions & 6 deletions src/EventNotification/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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[];

Expand All @@ -55,7 +58,7 @@ export type EventNotificationEntry = {
changes: EventNotificationChange[];
};

export type EventNotificationType = RequestBodyType & {
export type EventNotificationType = {
object: string;
entry: EventNotificationEntry[];
};
20 changes: 19 additions & 1 deletion src/Message/OutgoingMessage/CloudOutgoingMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions src/Message/OutgoingMessage/HostedOutgoingMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 70a11fa

Please sign in to comment.