Skip to content
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [1.4.0] - 2022-12-09
### Added
- Add missing models to send WhatsApp interactive messages
- Add missing models to send Apple Messages for Business listpicker messages.

## [1.3.6] - 2022-12-05
### Added
- Support for the Telegram channel
Expand Down
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,54 @@ response.then((result) => {
});
```

or send whatsapp interactive messages using the message builder
```javascript
const whatsAppInteractiveContent = {
type: 'list',
header: {
type: "text",
text: "your-header-content"
},
body: {
text: "your-text-message-content"
},
footer: {
text: "your-footer-content"
},
action: {
button: "cta-button-content",
sections: [{
title: "your-section-title1",
rows: [{
id: "unique-row-identifier1",
title: "row-title-content",
description: "row-description-content"
}]
},
{
title: "your-section-title2",
rows: [{
id: "unique-row-identifier2",
title: "row-title-content",
description: "row-description-content"
}]
}
]
}
};

const response = client.createMessage()
.setMessage(["00316012345678"], "TestSender", "Hello world?!")
.setAllowedChannels(["WhatsApp"])
.setInteractive(whatsAppInteractiveContent)
.send();

response.then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
```

### License
@cmdotcom/text-sdk is under the MIT license. See LICENSE file.
13 changes: 11 additions & 2 deletions lib/MessageApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as CMTypes from "../typescript-node-client/api";
import http = require('http');

export type Channel = "SMS" | "Viber" | "RCS" | "Apple Business Chat" | "WhatsApp" | "Telegram Messenger" | "Twitter" | "MobilePush" | "Facebook Messenger" | "Google Business Messages" | "Instagram";
export type Channel = "SMS" | "Viber" | "RCS" | "Apple Messages for Business" | "WhatsApp" | "Telegram Messenger" | "Twitter" | "MobilePush" | "Facebook Messenger" | "Google Business Messages" | "Instagram";
export type RichMessage = CMTypes.RichMessage;
export type Suggestion = CMTypes.Suggestion;
export type Template = CMTypes.Template;
export type MessagesResponse = CMTypes.MessagesResponse;

export type WhatsAppInteractive = CMTypes.WhatsAppInteractive;
/**
* Message client for the CM.com Platform
*/
Expand Down Expand Up @@ -142,6 +142,15 @@ export class Message extends CMTypes.MessageEnvelope {
return this;
}

/**
* Sets the WhatsAppInteractive Message
* @param template template definition and usage object
*/
public setInteractive(interactive: WhatsAppInteractive): Message {
this.getRichContent().conversation = [{ interactive: interactive }];
return this;
}

/**
* Sends the message to the CM.com Platform
*/
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cmdotcom/text-sdk",
"version": "1.3.6",
"version": "1.4.0",
"description": "Package to make it very easy to send text messages with CM.com",
"keywords": [
"cm",
Expand Down
99 changes: 99 additions & 0 deletions spec/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,103 @@ describe("MessageApiClient+MessageBuilder", () => {
return response.body.details === "Created 1 message(s)";
});
});

const whatsAppInteractiveContent = {
type: 'list',
header: {
type: "text",
text: "your-header-content"
},
body: {
text: "your-text-message-content"
},
footer: {
text: "your-footer-content"
},
action: {
button: "cta-button-content",
sections: [{
title: "your-section-title1",
rows: [{
id: "unique-row-identifier1",
title: "row-title-content",
description: "row-description-content"
}]
},
{
title: "your-section-title2",
rows: [{
id: "unique-row-identifier2",
title: "row-title-content",
description: "row-description-content"
}]
}
]
}
};

it("should create a valid http(s) request, when using the message-builder with a interactive WhatsApp message", () => {
const yourProductToken = "dddd";
const client = new MessageApiClient(yourProductToken);

const response = client.createMessage()
.setMessage(["00316012345678"], "TestSender", "Hello world?!")
.setAllowedChannels(["WhatsApp"])
.setInteractive(whatsAppInteractiveContent)
.send();

expect(response).to.be.eventually.fulfilled.and.to.satisfy((response) => {
return response.body.details === "Created 1 message(s)";
});
});

const appleListPickerrichMessage: RichMessage = {
text: "Check out my image",
listPicker: {
label: "Please, pick a card",
media: {
"mediaUri": "https://static.thenounproject.com/png/393234-200.png"
},
options: [{
label: "Ace of Hearts",
media: {
mediaUri: "https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.N7zZqoCvjxZZvwp2Zi1UVwHaH6%26pid%3D15.1&f=1"
}
},
{
label: "Ace of Spades",
media: {
mediaUri: "https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Fcdn.pixabay.com%2Fphoto%2F2013%2F07%2F12%2F12%2F01%2Fsuit-of-spades-145116_960_720.png&f=1"
}
},
{
label: "Ace of Diamonds",
media: {
mediaUri: "https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Fcdn.pixabay.com%2Fphoto%2F2012%2F05%2F07%2F18%2F37%2Fsuit-48941_960_720.png&f=1"
}
},
{
label: "Ace of Clubs",
media: {
mediaUri: "https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fthumb%2F8%2F8a%2FSuitClubs.svg%2F709px-SuitClubs.svg.png&f=1"
}
}
]
}
};

it("should create a valid http(s) request, when using the message-builder with a Apple for Business listpicker", () => {
const yourProductToken = "dddd";
const client = new MessageApiClient(yourProductToken);

const response = client.createMessage()
.setMessage(["00316012345678"], "TestSender", "Hello world?!")
.setAllowedChannels(["Apple Messages for Business"])
.setConversation([appleListPickerrichMessage])
.send();

expect(response).to.be.eventually.fulfilled.and.to.satisfy((response) => {
return response.body.details === "Created 1 message(s)";
});
});
});
Loading