Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9108d10

Browse filesBrowse files
Add missing models to send WhatsApp interactive messages plus Apple Messages for Business (#45)
* Add missing models to send WhatsApp interactive messages plus ABC List pickers * update changelog * update naming of ABC to Apple Messages For Business * Misc Updates Rename Apple Business chat to Apple Messages for Business Add Unit test and update models to lower case * fix unit test Co-authored-by: Soufyan Bargach <soufyanb2@hotmail.com>
1 parent 771d886 commit 9108d10
Copy full SHA for 9108d10

File tree

7 files changed

+639
-6
lines changed
Filter options

7 files changed

+639
-6
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [1.4.0] - 2022-12-09
2+
### Added
3+
- Add missing models to send WhatsApp interactive messages
4+
- Add missing models to send Apple Messages for Business listpicker messages.
5+
16
## [1.3.6] - 2022-12-05
27
### Added
38
- Support for the Telegram channel

‎README.md

Copy file name to clipboardExpand all lines: README.md
+49
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,54 @@ response.then((result) => {
9696
});
9797
```
9898

99+
or send whatsapp interactive messages using the message builder
100+
```javascript
101+
const whatsAppInteractiveContent = {
102+
type: 'list',
103+
header: {
104+
type: "text",
105+
text: "your-header-content"
106+
},
107+
body: {
108+
text: "your-text-message-content"
109+
},
110+
footer: {
111+
text: "your-footer-content"
112+
},
113+
action: {
114+
button: "cta-button-content",
115+
sections: [{
116+
title: "your-section-title1",
117+
rows: [{
118+
id: "unique-row-identifier1",
119+
title: "row-title-content",
120+
description: "row-description-content"
121+
}]
122+
},
123+
{
124+
title: "your-section-title2",
125+
rows: [{
126+
id: "unique-row-identifier2",
127+
title: "row-title-content",
128+
description: "row-description-content"
129+
}]
130+
}
131+
]
132+
}
133+
};
134+
135+
const response = client.createMessage()
136+
.setMessage(["00316012345678"], "TestSender", "Hello world?!")
137+
.setAllowedChannels(["WhatsApp"])
138+
.setInteractive(whatsAppInteractiveContent)
139+
.send();
140+
141+
response.then((result) => {
142+
console.log(result);
143+
}).catch((error) => {
144+
console.log(error);
145+
});
146+
```
147+
99148
### License
100149
@cmdotcom/text-sdk is under the MIT license. See LICENSE file.

‎lib/MessageApiClient.ts

Copy file name to clipboardExpand all lines: lib/MessageApiClient.ts
+11-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as CMTypes from "../typescript-node-client/api";
22
import http = require('http');
33

4-
export type Channel = "SMS" | "Viber" | "RCS" | "Apple Business Chat" | "WhatsApp" | "Telegram Messenger" | "Twitter" | "MobilePush" | "Facebook Messenger" | "Google Business Messages" | "Instagram";
4+
export type Channel = "SMS" | "Viber" | "RCS" | "Apple Messages for Business" | "WhatsApp" | "Telegram Messenger" | "Twitter" | "MobilePush" | "Facebook Messenger" | "Google Business Messages" | "Instagram";
55
export type RichMessage = CMTypes.RichMessage;
66
export type Suggestion = CMTypes.Suggestion;
77
export type Template = CMTypes.Template;
88
export type MessagesResponse = CMTypes.MessagesResponse;
9-
9+
export type WhatsAppInteractive = CMTypes.WhatsAppInteractive;
1010
/**
1111
* Message client for the CM.com Platform
1212
*/
@@ -142,6 +142,15 @@ export class Message extends CMTypes.MessageEnvelope {
142142
return this;
143143
}
144144

145+
/**
146+
* Sets the WhatsAppInteractive Message
147+
* @param template template definition and usage object
148+
*/
149+
public setInteractive(interactive: WhatsAppInteractive): Message {
150+
this.getRichContent().conversation = [{ interactive: interactive }];
151+
return this;
152+
}
153+
145154
/**
146155
* Sends the message to the CM.com Platform
147156
*/

‎package-lock.json

Copy file name to clipboardExpand all lines: package-lock.json
+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Copy file name to clipboardExpand all lines: package.json
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cmdotcom/text-sdk",
3-
"version": "1.3.6",
3+
"version": "1.4.0",
44
"description": "Package to make it very easy to send text messages with CM.com",
55
"keywords": [
66
"cm",

‎spec/api.spec.ts

Copy file name to clipboardExpand all lines: spec/api.spec.ts
+99
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,103 @@ describe("MessageApiClient+MessageBuilder", () => {
170170
return response.body.details === "Created 1 message(s)";
171171
});
172172
});
173+
174+
const whatsAppInteractiveContent = {
175+
type: 'list',
176+
header: {
177+
type: "text",
178+
text: "your-header-content"
179+
},
180+
body: {
181+
text: "your-text-message-content"
182+
},
183+
footer: {
184+
text: "your-footer-content"
185+
},
186+
action: {
187+
button: "cta-button-content",
188+
sections: [{
189+
title: "your-section-title1",
190+
rows: [{
191+
id: "unique-row-identifier1",
192+
title: "row-title-content",
193+
description: "row-description-content"
194+
}]
195+
},
196+
{
197+
title: "your-section-title2",
198+
rows: [{
199+
id: "unique-row-identifier2",
200+
title: "row-title-content",
201+
description: "row-description-content"
202+
}]
203+
}
204+
]
205+
}
206+
};
207+
208+
it("should create a valid http(s) request, when using the message-builder with a interactive WhatsApp message", () => {
209+
const yourProductToken = "dddd";
210+
const client = new MessageApiClient(yourProductToken);
211+
212+
const response = client.createMessage()
213+
.setMessage(["00316012345678"], "TestSender", "Hello world?!")
214+
.setAllowedChannels(["WhatsApp"])
215+
.setInteractive(whatsAppInteractiveContent)
216+
.send();
217+
218+
expect(response).to.be.eventually.fulfilled.and.to.satisfy((response) => {
219+
return response.body.details === "Created 1 message(s)";
220+
});
221+
});
222+
223+
const appleListPickerrichMessage: RichMessage = {
224+
text: "Check out my image",
225+
listPicker: {
226+
label: "Please, pick a card",
227+
media: {
228+
"mediaUri": "https://static.thenounproject.com/png/393234-200.png"
229+
},
230+
options: [{
231+
label: "Ace of Hearts",
232+
media: {
233+
mediaUri: "https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.N7zZqoCvjxZZvwp2Zi1UVwHaH6%26pid%3D15.1&f=1"
234+
}
235+
},
236+
{
237+
label: "Ace of Spades",
238+
media: {
239+
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"
240+
}
241+
},
242+
{
243+
label: "Ace of Diamonds",
244+
media: {
245+
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"
246+
}
247+
},
248+
{
249+
label: "Ace of Clubs",
250+
media: {
251+
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"
252+
}
253+
}
254+
]
255+
}
256+
};
257+
258+
it("should create a valid http(s) request, when using the message-builder with a Apple for Business listpicker", () => {
259+
const yourProductToken = "dddd";
260+
const client = new MessageApiClient(yourProductToken);
261+
262+
const response = client.createMessage()
263+
.setMessage(["00316012345678"], "TestSender", "Hello world?!")
264+
.setAllowedChannels(["Apple Messages for Business"])
265+
.setConversation([appleListPickerrichMessage])
266+
.send();
267+
268+
expect(response).to.be.eventually.fulfilled.and.to.satisfy((response) => {
269+
return response.body.details === "Created 1 message(s)";
270+
});
271+
});
173272
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.