Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added whats app reaction #964

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions packages/messages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,15 @@ for general use will be listed as having 'General Availability'. Channels which
are currently part of a Beta program will be listed as 'Beta'. This table
details the current release status of each channel implemented in this SDK:

| Channel | API Release Status |
|--------------------|:--------------------:|
| SMS | General Availability |
| MMS | General Availability |
| RCS | Beta |
| Facebook Messenger | General Availability |
| WhatsApp | General Availability |
| Viber | General Availability |
| Channel | API Release Status |
|---------------------|:--------------------:|
| SMS | General Availability |
| MMS | General Availability |
| RCS | Beta |
| Facebook Messenger | General Availability |
| WhatsApp | General Availability |
| WhatsApp (reaction) | Beta |
| Viber | General Availability |

[signup]: https://dashboard.nexmo.com/sign-up?utm_source=DEV_REL&utm_medium=github&utm_campaign=node-server-sdk

Expand Down
101 changes: 101 additions & 0 deletions packages/messages/__tests__/__dataSets__/whatsApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import {
WhatsAppVideoRequest,
UpdateMessageStatus,
UpdateMessageRequest,
WhatsAppReactionRequest,
WhatsAppReactionParams,
WhatsAppReaction,
} from '../../lib';

import { Audio } from '../../lib/classes/WhatsApp/Audio';
Expand Down Expand Up @@ -1035,4 +1038,102 @@ export default [
],
expected: true
},
{
label: 'send reaction',
request: [
'/v1/messages',
'POST',
{
from: '12126875309',
to: '14152739164',
channel: 'whatsapp',
message_type: 'reaction',
client_ref: 'my-ref',
context: {
message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
},
webhook_version: 'v1',
webhook_url: 'https://example.com',
reaction: {
action: 'react',
emoji: '😄',
}
} as WhatsAppReactionRequest,
],
response: [
200,
{
message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
},
],
method: 'POST',
clientMethod: 'send',
parameters: [
new WhatsAppReaction({
from: '12126875309',
to: '14152739164',
clientRef: 'my-ref',
context: {
messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
},
webhookVersion: 'v1',
webhookUrl: 'https://example.com',
reaction: {
action: 'react',
emoji: '😄',
}
} as WhatsAppReactionParams),
],
expected: {
messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
} as MessageSuccess,
},
{
label: 'remove reaction',
request: [
'/v1/messages',
'POST',
{
from: '12126875309',
to: '14152739164',
channel: 'whatsapp',
message_type: 'reaction',
client_ref: 'my-ref',
context: {
message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
},
webhook_version: 'v1',
webhook_url: 'https://example.com',
reaction: {
action: 'unreact',
}
} as WhatsAppReactionRequest,
],
response: [
200,
{
message_uuid: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
},
],
method: 'POST',
clientMethod: 'send',
parameters: [
new WhatsAppReaction({
from: '12126875309',
to: '14152739164',
clientRef: 'my-ref',
context: {
messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
},
webhookVersion: 'v1',
webhookUrl: 'https://example.com',
reaction: {
action: 'unreact',
}
} as WhatsAppReactionParams),
],
expected: {
messageUUID: '1d4723b0-9134-4440-8cf0-e9f39ccb1c6a',
} as MessageSuccess,
}
];
71 changes: 71 additions & 0 deletions packages/messages/lib/classes/WhatsApp/WhatsAppReaction.ts
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;
}
}
}
1 change: 1 addition & 0 deletions packages/messages/lib/classes/WhatsApp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './WhatsAppSticker';
export * from './WhatsAppTemplate';
export * from './WhatsAppText';
export * from './WhatsAppVideo';
export * from './WhatsAppReaction';
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;
}
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;
4 changes: 4 additions & 0 deletions packages/messages/lib/types/Channels/WhatsApp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { WhatsAppStickerParams } from './WhatsAppStickerParams';
import { WhatsAppTemplateParams } from './WhatsAppTemplateParams';
import { WhatsAppTextParams } from './WhatsAppTextParams';
import { WhatsAppVideoParams } from './WhatsAppVideoParams';
import { WhatsAppReactionParams } from './WhatsAppReactionParams';
import { Channels } from '../../../enums';

export * from './WhatsAppAudioParams';
Expand All @@ -23,6 +24,8 @@ export * from './WhatsAppTemplateType';
export * from './WhatsAppTextParams';
export * from './WhatsAppVideoParams';
export * from './WhatsAppParams';
export * from './WhatsAppReactionParams';
export * from './WhatAppReactionType';

/**
* Represents a union type that can be any of the WhatsApp-specific message
Expand All @@ -40,6 +43,7 @@ export type AnyWhatsAppParams =
| WhatsAppStickerParams
| WhatsAppTemplateParams
| WhatsAppTextParams
| WhatsAppReactionParams
| WhatsAppVideoParams;

/**
Expand Down
69 changes: 69 additions & 0 deletions packages/messages/lib/types/Requests/WhatsAppReactionRequest.ts
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
}

}
1 change: 1 addition & 0 deletions packages/messages/lib/types/Requests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export * from './WhatsAppStickerIdRequest';
export * from './WhatsAppTemplateRequest';
export * from './WhatsAppTextRequest';
export * from './UpdateMessageRequest';
export * from './WhatsAppReactionRequest';
Loading