Skip to content

Commit

Permalink
fix(messages): added missing context to whats app
Browse files Browse the repository at this point in the history
Added missing params for files and vCard
  • Loading branch information
manchuck committed Mar 18, 2024
1 parent 0489db3 commit 67c5200
Show file tree
Hide file tree
Showing 29 changed files with 150 additions and 111 deletions.
2 changes: 2 additions & 0 deletions packages/messages/__tests__/__dataSets__/mms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ export default [
message_type: 'vcard',
vcard: {
url: 'https://example.com',
caption: 'My vcard',
},
client_ref: 'my-ref',
} as MMSVcardRequest,
Expand All @@ -439,6 +440,7 @@ export default [
to: '14152739164',
vcard: {
url: 'https://example.com',
caption: 'My vcard',
},
clientRef: 'my-ref',
} as MessageParamsVcard),
Expand Down
36 changes: 0 additions & 36 deletions packages/messages/__tests__/__dataSets__/viber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,6 @@ export default [
url: 'https://example.com',
},
client_ref: 'my-ref',
viber_service: {
category: ViberCategory.PROMOTION,
ttl: 42,
type: 'type',
action: {
url: 'https://example.com',
text: 'viber text',
},
},
} as ViberVideoRequest,
],
response: [
Expand All @@ -383,15 +374,6 @@ export default [
url: 'https://example.com',
},
clientRef: 'my-ref',
viberService: {
category: ViberCategory.PROMOTION,
ttl: 42,
type: 'type',
action: {
url: 'https://example.com',
text: 'viber text',
} as ViberAction,
} as ViberService,
} as ViberVideoParams),
],
expected: {
Expand Down Expand Up @@ -449,15 +431,6 @@ export default [
name: 'Keyboard Cat',
},
client_ref: 'my-ref',
viber_service: {
category: ViberCategory.PROMOTION,
ttl: 42,
type: 'type',
action: {
url: 'https://example.com',
text: 'viber text',
},
},
} as ViberFileRequest,
],
response: [
Expand All @@ -477,15 +450,6 @@ export default [
name: 'Keyboard Cat',
},
clientRef: 'my-ref',
viberService: {
category: ViberCategory.PROMOTION,
ttl: 42,
type: 'type',
action: {
url: 'https://example.com',
text: 'viber text',
} as ViberAction,
} as ViberService,
} as ViberFileParams),
],
expected: {
Expand Down
11 changes: 9 additions & 2 deletions packages/messages/__tests__/__dataSets__/whatsApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default [
} as MessageSuccess,
},
{
label: 'send WhatsApp text with client ref',
label: 'send WhatsApp text with client ref and context',
request: [
'/v1/messages',
'POST',
Expand All @@ -81,6 +81,9 @@ export default [
channel: 'whatsapp',
message_type: 'text',
client_ref: 'my-ref',
context: {
message_uuid: '00000000-0000-0000-0000-000000000000',
},
text: 'Too many secrets',
webhook_url: 'https://example.com',
webhook_version: 'v1',
Expand All @@ -100,6 +103,9 @@ export default [
to: '14152739164',
clientRef: 'my-ref',
text: 'Too many secrets',
context: {
messageUUID: '00000000-0000-0000-0000-000000000000',
},
webhookUrl: 'https://example.com',
webhookVersion: 'v1',
} as WhatsAppTextParams),
Expand Down Expand Up @@ -479,6 +485,7 @@ export default [
file: {
url: 'https://example.com/my-file.png',
caption: 'a snake on a plane',
name: 'my-file.png',
},
} as WhatsAppFileRequest,
],
Expand All @@ -497,8 +504,8 @@ export default [
clientRef: 'my-ref',
file: {
url: 'https://example.com/my-file.png',

caption: 'a snake on a plane',
name: 'my-file.png',
},
} as WhatsAppFileParams),
],
Expand Down
4 changes: 2 additions & 2 deletions packages/messages/lib/classes/MMS/MMSVcard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export class MMSVcard
* to: TO_NUMBER,
* from: FROM_NUMBER,
* vcard: {
* name: 'John Doe',
* phoneNumber: '15555555555',
* url: 'https://example.com/vcard.vcf',
* caption: 'Download my contact information',
* },
* clientRef: 'my-personal-reference',
* }));
Expand Down
6 changes: 3 additions & 3 deletions packages/messages/lib/classes/Messenger/MessengerFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbstractFileMessage } from '../AbstractFileMessage';
import { MessageParamsFile, MessengerFileParams } from '../../types';
import { MessageParams, MessengerFileParams } from '../../types';

/**
* Represents a file message for the Messenger channel.
Expand All @@ -8,7 +8,7 @@ import { MessageParamsFile, MessengerFileParams } from '../../types';
*/
export class MessengerFile
extends AbstractFileMessage
implements MessageParamsFile
implements MessengerFileParams, MessageParams
{
/**
* The channel for this message (always 'messenger').
Expand Down Expand Up @@ -42,7 +42,7 @@ export class MessengerFile
* console.log(`Message sent successfully with UUID ${messageUUID}`);
* ```
*/
public constructor(params: MessengerFileParams) {
public constructor(params: MessageParams & MessengerFileParams) {
super(params);
this.messenger = params.messenger;
this.channel = 'messenger';
Expand Down
7 changes: 1 addition & 6 deletions packages/messages/lib/classes/Viber/ViberFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ import { ViberFileParams } from '../../types';
*
* @group Viber
*/
export class ViberFile
extends AbstractFileMessage
implements ViberFileParams
{
export class ViberFile extends AbstractFileMessage implements ViberFileParams {
public channel: 'viber_service';
public viberService;

/**
* Send a file message using the Viber Service channel.
Expand Down Expand Up @@ -41,7 +37,6 @@ export class ViberFile
*/
constructor(params: ViberFileParams) {
super(params);
this.viberService = params.viberService;
this.channel = 'viber_service';
}
}
6 changes: 5 additions & 1 deletion packages/messages/lib/classes/WhatsApp/WhatsAppAudio.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbstractAudioMessage } from '../AbstractAudioMessage';
import { WhatsAppAudioParams } from '../../types';
import { WhatsAppAudioParams, WhatsAppContext } from '../../types';

/**
* Represents an audio message for WhatsApp.
Expand All @@ -12,6 +12,7 @@ export class WhatsAppAudio
{
public channel: 'whatsapp';

public context?: WhatsAppContext;
/**
* Sends an audio message to a WhatsApp user.
*
Expand All @@ -36,5 +37,8 @@ export class WhatsAppAudio
public constructor(params: WhatsAppAudioParams) {
super(params);
this.channel = 'whatsapp';
if (params.context) {
this.context = params.context;
}
}
}
11 changes: 10 additions & 1 deletion packages/messages/lib/classes/WhatsApp/WhatsAppCustom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { AbstractMessage } from '../AbstractMessage';
import { WhatsAppCustomType, WhatsAppCustomParams } from '../../types';
import {
WhatsAppCustomType,
WhatsAppCustomParams,
WhatsAppContext,
} from '../../types';

/**
* Represents a custom message for WhatsApp.
Expand All @@ -14,6 +18,8 @@ export class WhatsAppCustom
public messageType: 'custom';
public custom: WhatsAppCustomType;

public context?: WhatsAppContext;

/**
* Sends a custom message to a WhatsApp user.
*
Expand Down Expand Up @@ -43,5 +49,8 @@ export class WhatsAppCustom
this.custom = params.custom;
this.channel = 'whatsapp';
this.messageType = 'custom';
if (params.context) {
this.context = params.context;
}
}
}
11 changes: 8 additions & 3 deletions packages/messages/lib/classes/WhatsApp/WhatsAppFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Channels } from '../../enums';
import { AbstractFileMessage } from '../AbstractFileMessage';
import { WhatsAppFileParams } from '../../types';
import { WhatsAppFileParams, WhatsAppContext } from '../../types';

/**
* Represents a file message for WhatsApp.
Expand All @@ -10,7 +11,9 @@ export class WhatsAppFile
extends AbstractFileMessage
implements WhatsAppFileParams
{
public channel: 'whatsapp';
public channel = Channels.WHATSAPP;

public context?: WhatsAppContext;

/**
* Send a WhatsApp file message.
Expand All @@ -34,6 +37,8 @@ export class WhatsAppFile
*/
public constructor(params: WhatsAppFileParams) {
super(params);
this.channel = 'whatsapp';
if (params.context) {
this.context = params.context;
}
}
}
6 changes: 5 additions & 1 deletion packages/messages/lib/classes/WhatsApp/WhatsAppImage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbstractImageMessage } from '../AbstractImageMessage';
import { WhatsAppImageParams } from '../../types';
import { WhatsAppImageParams, WhatsAppContext } from '../../types';

/**
* Represents an image message for WhatsApp.
Expand All @@ -12,6 +12,7 @@ export class WhatsAppImage
{
public channel: 'whatsapp';

public context?: WhatsAppContext;
/**
* Sends an image message to a WhatsApp user.
*
Expand All @@ -36,5 +37,8 @@ export class WhatsAppImage
public constructor(params: WhatsAppImageParams) {
super(params);
this.channel = 'whatsapp';
if (params.context) {
this.context = params.context;
}
}
}
14 changes: 11 additions & 3 deletions packages/messages/lib/classes/WhatsApp/WhatsAppSticker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { AbstractMessage } from '../AbstractMessage';
import { WhatsAppStickerParams } from '../../types';
import { WhatsAppStickerIdType } from '../../types';
import { WhatsAppStickerUrlType } from '../../types';
import {
WhatsAppStickerParams,
WhatsAppStickerIdType,
WhatsAppStickerUrlType,
WhatsAppContext,
} from '../../types';

/**
* Represents a sticker message for WhatsApp.
Expand All @@ -16,6 +19,8 @@ export class WhatsAppSticker
public messageType: 'sticker';
public sticker: WhatsAppStickerIdType | WhatsAppStickerUrlType;

public context?: WhatsAppContext;

/**
* Send a sticker message to a WhatsApp user.
*
Expand Down Expand Up @@ -59,5 +64,8 @@ export class WhatsAppSticker
this.sticker = params.sticker;
this.channel = 'whatsapp';
this.messageType = 'sticker';
if (params.context) {
this.context = params.context;
}
}
}
14 changes: 11 additions & 3 deletions packages/messages/lib/classes/WhatsApp/WhatsAppTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { AbstractMessage } from '../AbstractMessage';
import { WhatsAppTemplateParams } from '../../types';
import { WhatsAppPolicyType } from '../../types';
import { WhatsAppTemplateType } from '../../types';
import {
WhatsAppTemplateParams,
WhatsAppPolicyType,
WhatsAppTemplateType,
WhatsAppContext,
} from '../../types';

/**
* Represents a template message for WhatsApp.
Expand All @@ -17,6 +20,8 @@ export class WhatsAppTemplate
public whatsapp: WhatsAppPolicyType;
public template: WhatsAppTemplateType;

public context?: WhatsAppContext;

/**
* Send a template message to a WhatsApp user.
*
Expand Down Expand Up @@ -52,5 +57,8 @@ export class WhatsAppTemplate
this.template = params.template;
this.channel = 'whatsapp';
this.messageType = 'template';
if (params.context) {
this.context = params.context;
}
}
}
6 changes: 5 additions & 1 deletion packages/messages/lib/classes/WhatsApp/WhatsAppText.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbstractTextMessage } from '../AbstractTextMessage';
import { WhatsAppTextParams } from '../../types';
import { WhatsAppTextParams, WhatsAppContext } from '../../types';

/**
* Represents a text message for WhatsApp.
Expand All @@ -12,6 +12,7 @@ export class WhatsAppText
{
public channel: 'whatsapp';

public context?: WhatsAppContext;
/**
* Send a WhatsApp text message.
*
Expand All @@ -33,5 +34,8 @@ export class WhatsAppText
public constructor(params: WhatsAppTextParams) {
super(params);
this.channel = 'whatsapp';
if (params.context) {
this.context = params.context;
}
}
}
Loading

0 comments on commit 67c5200

Please sign in to comment.