-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
278 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/messages/lib/classes/WhatsApp/WhatsAppReaction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { AbstractMessage } from '../AbstractMessage'; | ||
import { | ||
WhatsAppReactionParams, | ||
WhatsAppReactionType, | ||
WhatsAppContext, | ||
} from '../../types'; | ||
|
||
/** | ||
* Represents a reaction message for WhatsApp. | ||
* | ||
* @group WhatsApp | ||
*/ | ||
export class WhatsAppReaction | ||
extends AbstractMessage | ||
implements WhatsAppReactionParams | ||
{ | ||
public channel: 'whatsapp'; | ||
public messageType: 'reaction'; | ||
public reaction: WhatsAppReactionType; | ||
|
||
public context?: WhatsAppContext; | ||
|
||
/** | ||
* Sends a reaction message to a WhatsApp user. | ||
* | ||
* @param {WhatsAppReactionParams} params - The parameters for creating a WhatsApp reaction message. | ||
* @example | ||
* Send a reaction | ||
* ```ts | ||
* import { WhatsAppReaction } from '@vonage/messages'; | ||
* | ||
* const { messageUUID } = await messagesClient.send(new WhatsAppReaction({ | ||
* to: TO_NUMBER, | ||
* from: FROM_NUMBER, | ||
* reaction: { | ||
* action: 'react', | ||
* emoji: '😍', | ||
* } | ||
* clientRef: 'my-personal-reference', | ||
* })); | ||
* | ||
* console.log(`Message sent successfully with UUID ${messageUUID}`); | ||
* ``` | ||
* | ||
* @example | ||
* Remove reaction | ||
* ```ts | ||
* import { WhatsAppReaction } from '@vonage/messages'; | ||
* | ||
* const { messageUUID } = await messagesClient.send(new WhatsAppReaction({ | ||
* to: TO_NUMBER, | ||
* from: FROM_NUMBER, | ||
* reaction: { | ||
* action: 'unreact', | ||
* } | ||
* clientRef: 'my-personal-reference', | ||
* })); | ||
* | ||
* console.log(`Message sent successfully with UUID ${messageUUID}`); | ||
* ``` | ||
*/ | ||
public constructor(params: WhatsAppReactionParams) { | ||
super(params); | ||
this.channel = 'whatsapp'; | ||
this.messageType = 'reaction'; | ||
this.reaction = params.reaction; | ||
if (params.context) { | ||
this.context = params.context; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/messages/lib/types/Channels/WhatsApp/WhatAppReactionType.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export type WhatsAppReactionType = { | ||
/** | ||
* The action taken. | ||
*/ | ||
action: 'react' | 'unreact'; | ||
|
||
/** | ||
* The emoji used as a reaction. | ||
*/ | ||
emoji?: string; | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/messages/lib/types/Channels/WhatsApp/WhatsAppReactionParams.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { WhatsAppParams } from './WhatsAppParams'; | ||
import { WhatsAppReactionType } from './WhatAppReactionType'; | ||
/** | ||
* Represents WhatsApp reaction message parameters. | ||
* | ||
* @group WhatsApp | ||
* @category Parameters | ||
*/ | ||
export type WhatsAppReactionParams = { | ||
reaction: WhatsAppReactionType; | ||
} & WhatsAppParams; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/messages/lib/types/Requests/WhatsAppReactionRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
export type WhatsAppReactionRequest = { | ||
/** | ||
* A client-defined reference string for the message. | ||
*/ | ||
client_ref: string; | ||
|
||
/** | ||
* The type of the message, which is 'reaction' for a text message. | ||
*/ | ||
message_type: 'reaction'; | ||
|
||
/** | ||
* The recipient's identifier. | ||
*/ | ||
to: string; | ||
|
||
/** | ||
* The sender's identifier. | ||
*/ | ||
from: string; | ||
|
||
/** | ||
* The channel through which the message will be sent, which is 'whatsapp' for WhatsApp. | ||
*/ | ||
channel: 'whatsapp'; | ||
|
||
/** | ||
* Specifies which version of the Messages API will be used to send Status | ||
* Webhook messages for this particular message. For example, if v0.1 is | ||
* set, then the JSON body of Status Webhook messages for this message will | ||
* be sent in Messages v0.1 format. Over-rides account-level and | ||
* application-level API version settings on a per-message basis. | ||
*/ | ||
webhook_version: 'v0.1' | 'v1'; | ||
|
||
/** | ||
* Specifies the URL to which Status Webhook messages will be sent for this | ||
* particular message. Over-rides account-level and application-level Status | ||
* Webhook url settings on a per-message basis. | ||
*/ | ||
webhook_url: string; | ||
|
||
/** | ||
* A context used for quoting/replying/reacting to a specific message in a | ||
* conversation. When used for quoting or replying, the WhatsApp UI will | ||
* display the new message along with a contextual bubble that displays the | ||
* quoted/replied to message's content. When used for reacting the WhatsApp | ||
* UI will display the reaction emoji below the reacted to message. | ||
*/ | ||
context: { | ||
/** | ||
* The UUID of the message being quoted/replied/reacted to. | ||
*/ | ||
message_uuid: string; | ||
}; | ||
|
||
reaction: { | ||
/** | ||
* The action taken. | ||
*/ | ||
action: 'react' | 'unreact'; | ||
|
||
/** | ||
* The emoji used as a reaction. | ||
*/ | ||
emoji?: string | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters