Skip to content

Commit 305e9cf

Browse files
committed
merge
2 parents c3069f6 + 489a339 commit 305e9cf

File tree

4 files changed

+569
-7
lines changed

4 files changed

+569
-7
lines changed

articles/communication-services/quickstarts/advanced-messaging/whatsapp/includes/get-started/messages-get-started-net.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ The following classes and interfaces handle some of the major features of the Az
3030
| `NotificationMessagesClient` | Connects to your Azure Communication Services resource. It sends the messages. |
3131
| `MessageTemplate` | Defines which template you use and the content of the template properties for your message. |
3232
| `TemplateNotificationContent` | Defines the "who" and the "what" of the template message you intend to send. |
33-
| `TextNotificationContent` | Defines the "who" and the "what" of the text message you intend to send. |
34-
| `MediaNotificationContent` | Defines the "who" and the "what" of the media message you intend to send. |
33+
| `TextNotificationContent` | Defines the "who" and the "what" of the text message you intend to send. |
34+
| `ImageNotificationContent` | Defines the "who" and the "what" of the image media message you intend to send. |
35+
| `DocumentNotificationContent` | Defines the "who" and the "what" of the Document media message you intend to send. |
36+
| `VideoNotificationContent` | Defines the "who" and the "what" of the Video media message you intend to send. |
37+
| `AudioNotificationContent` | Defines the "who" and the "what" of the Audio media message you intend to send. | |
3538

3639
> [!NOTE]
3740
> For more information, see the Azure SDK for .NET reference [Azure.Communication.Messages Namespace](/dotnet/api/azure.communication.messages).
@@ -57,7 +60,7 @@ Follow these steps to add required code snippets to the Main function of your `P
5760
- [Send a video media message to a WhatsApp user](#send-a-video-media-message-to-a-whatsapp-user).
5861

5962
> [!IMPORTANT]
60-
> To send a text message to a WhatsApp user, the WhatsApp user must first send a message to the WhatsApp Business Account. For more information, see [Start sending messages between business and WhatsApp user](#start-sending-messages-between-a-business-and-a-whatsapp-user).
63+
> To send a text or media message to a WhatsApp user, the WhatsApp user must first send a message to the WhatsApp Business Account. For more information, see [Start sending messages between business and WhatsApp user](#start-sending-messages-between-a-business-and-a-whatsapp-user).
6164
6265
### Send a text message to a WhatsApp user
6366

articles/communication-services/quickstarts/advanced-messaging/whatsapp/includes/interactive/messages-quickstart-interactive-messages-net.md

Lines changed: 326 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ title: Include file
33
description: Include file
44
services: azure-communication-services
55
author: shamkh
6+
manager: camilo.ramirez
67
ms.service: azure-communication-services
8+
ms.subservice: azure-communication-services
79
ms.subservice: advanced-messaging
810
ms.date: 12/15/2024
911
ms.topic: include
@@ -17,6 +19,328 @@ ms.author: shamkh
1719
- Active WhatsApp phone number to receive messages.
1820
- .NET development environment, such as [Visual Studio](https://visualstudio.microsoft.com/downloads/), [Visual Studio Code](https://code.visualstudio.com/Download), or [.NET CLI](https://dotnet.microsoft.com/download).
1921

20-
## Set up environment
22+
## Set up the environment
23+
24+
[!INCLUDE [Setting up for .NET Application](../dot-net-application-setup.md)]
25+
26+
## Object model
27+
28+
The following classes and interfaces handle some of the major features of the Azure Communication Services Messages SDK for .NET.
29+
30+
| Class Name | Description |
31+
| --- |--- |
32+
| `NotificationMessagesClient` | Connects to your Azure Communication Services resource. It sends the messages. |
33+
| `InteractiveNotificationContent` | Defines the interactive message business can send to user. |
34+
| `InteractiveMessage` | Defines interactive message content.|
35+
| `WhatsAppListActionBindings` | Defines WhatsApp List interactive message properties binding. |
36+
| `WhatsAppButtonActionBindings`| Defines WhatsApp Button interactive message properties binding.|
37+
| `WhatsAppUrlActionBindings` | Defines WhatsApp Url interactive message properties binding.|
38+
| `TextMessageContent` | Defines the text content for Interactive message body, footer, header. |
39+
| `VideoMessageContent` | Defines the video content for Interactive message header. |
40+
| `DocumentMessageContent` | Defines the document content for Interactive message header. |
41+
| `ImageMessageContent` | Defines the image content for Interactive message header.|
42+
| `ActionGroupContent` | Defines the ActionGroup or ListOptions content for Interactive message.|
43+
| `ButtonSetContent` | Defines the Reply Buttons content for Interactive message. |
44+
| `LinkContent` | Defines the Url or Click-To-Action content for Interactive message. |
45+
46+
## Common configuration
47+
48+
Follow these steps to add required code snippets to your .NET program.
49+
50+
- [Authenticate the client](#authenticate-the-client)
51+
- [Set channel registration ID](#set-channel-registration-id)
52+
- [Set recipient list](#set-recipient-list)
53+
54+
[!INCLUDE [Common setting for using Advanced Messages SDK](../common-setting.md)]
55+
56+
## Code examples
57+
58+
The Messages SDK supports the following WhatsApp Interactive messages:
59+
60+
- [Send an Interactive List options message to a WhatsApp user](#send-an-interactive-list-options-message-to-a-whatsapp-user).
61+
- [Send an Interactive Reply Button message to a WhatsApp user](#send-an-interactive-reply-button-message-to-a-whatsapp-user).
62+
- [Send an Interactive Click-to-action URL-based message to a WhatsApp user](#send-an-interactive-click-to-action-url-based-message-to-a-whatsapp-user).
63+
64+
### Send an Interactive List options message to a WhatsApp user
65+
66+
The Messages SDK enables Contoso to send interactive WhatsApp messages when initiated by WhatsApp users. To send list messages:
67+
- [WhatsApp Channel ID](#set-channel-registration-id).
68+
- [Recipient Phone Number in E.164 format](#set-recipient-list).
69+
- List Message can be created using the given properties:
70+
71+
| Action type | Description |
72+
| --- | --- |
73+
| `ActionGroupContent` | This class defines the title of the group content and array of the group. |
74+
| `ActionGroup` | This class defines the title of the group and array of the group items. |
75+
| `ActionGroupItem` | This class defines ID, Title, and description of the group Item. |
76+
| `WhatsAppListActionBindings`| This class defines the `ActionGroupContent` binding with the interactive message. |
77+
78+
> [!IMPORTANT]
79+
> To send an interactive message to a WhatsApp user, the WhatsApp user must first send a message to the WhatsApp Business Account. For more information, see [Start sending messages between business and WhatsApp user](#start-sending-messages-between-a-business-and-a-whatsapp-user).
80+
81+
In this example, the business sends an interactive shipping options message to the user:
82+
83+
```csharp
84+
using Azure.Communication.Messages;
85+
using Azure.Communication.Messages.Models;
86+
87+
public async Task SendWhatsAppListMessage()
88+
{
89+
var actionItemsList1 = new List<ActionGroupItem>
90+
{
91+
new ActionGroupItem("priority_express", "Priority Mail Express", "Next Day to 2 Days"),
92+
new ActionGroupItem("priority_mail", "Priority Mail", "1–3 Days")
93+
};
94+
95+
var actionItemsList2 = new List<ActionGroupItem>
96+
{
97+
new ActionGroupItem("usps_ground_advantage", "USPS Ground Advantage", "2-5 Days"),
98+
new ActionGroupItem("media_mail", "Media Mail", "2-8 Days")
99+
};
100+
101+
var groups = new List<ActionGroup>
102+
{
103+
new ActionGroup("I want it ASAP!", actionItemsList1),
104+
new ActionGroup("I can wait a bit", actionItemsList2)
105+
};
106+
107+
var actionGroupContent = new ActionGroupContent("Shipping Options", groups);
108+
109+
var interactionMessage = new InteractiveMessage(
110+
new TextMessageContent("Test Body"),
111+
new WhatsAppListActionBindings(actionGroupContent)
112+
);
113+
interactionMessage.Header = new TextMessageContent("Test Header");
114+
interactionMessage.Footer = new TextMessageContent("Test Footer");
115+
116+
var interactiveMessageContent = new InteractiveNotificationContent(
117+
channelRegistrationId,
118+
recipientList,
119+
interactionMessage
120+
);
121+
122+
SendMessageResult response = await notificationMessagesClient.SendAsync(interactiveMessageContent);
123+
Console.WriteLine($"Message with ID {response.Receipts[0].MessageId} was successfully sent.");
124+
}
125+
```
126+
127+
### Send an Interactive Reply Button message to a WhatsApp user
128+
129+
To send reply button messages:
130+
131+
- [WhatsApp Channel ID](#set-channel-registration-id).
132+
- [Recipient Phone Number in E.164 format](#set-recipient-list).
133+
134+
Reply Button Messages can be created using the following properties:
135+
136+
| Action type | Description |
137+
| --- | --- |
138+
| `ButtonSetContent` | This class defines button set content for reply button messages. |
139+
| `ButtonContent` | This class defines ID and title of the reply buttons. |
140+
| `WhatsAppButtonActionBindings`| This class defines the `ButtonSetContent` binding with the interactive message. |
141+
142+
```csharp
143+
public async Task SendWhatsAppReplyButtonMessage()
144+
{
145+
var replyButtonActionList = new List<ButtonContent>
146+
{
147+
new ButtonContent("cancel", "Cancel"),
148+
new ButtonContent("agree", "Agree")
149+
};
150+
151+
var buttonSet = new ButtonSetContent(replyButtonActionList);
152+
153+
var interactionMessage = new InteractiveMessage(
154+
new TextMessageContent("Test Body"),
155+
new WhatsAppButtonActionBindings(buttonSet)
156+
);
157+
interactionMessage.Header = new TextMessageContent("Test Header");
158+
interactionMessage.Footer = new TextMessageContent("Test Footer");
159+
160+
var interactiveMessageContent = new InteractiveNotificationContent(
161+
channelRegistrationId,
162+
recipientList,
163+
interactionMessage
164+
);
165+
166+
SendMessageResult response = await notificationMessagesClient.SendAsync(interactiveMessageContent);
167+
Console.WriteLine($"Message with ID {response.Receipts[0].MessageId} was successfully sent.");
168+
}
169+
```
170+
171+
### Send an Interactive Click-to-action URL-based message to a WhatsApp user
172+
173+
To send Click-To-Action or URL-based messages:
174+
175+
- [WhatsApp Channel ID](#set-channel-registration-id).
176+
- [Recipient Phone Number in E.164 format](#set-recipient-list).
177+
178+
Click-To-Action Messages can be created using the following properties:
179+
180+
| Action type | Description |
181+
| --- | --- |
182+
| `LinkContent` | This class defines URL or link content for a message. |
183+
| `WhatsAppUrlActionBindings` | This class defines the `LinkContent` binding with the interactive message. |
184+
185+
```csharp
186+
public async Task SendWhatsAppClickToActionMessage()
187+
{
188+
var urlAction = new LinkContent("Test Url", new Uri("https://example.com/audio.mp3"));
189+
190+
var interactionMessage = new InteractiveMessage(
191+
new TextMessageContent("Test Body"),
192+
new WhatsAppUrlActionBindings(urlAction)
193+
);
194+
interactionMessage.Header = new TextMessageContent("Test Header");
195+
interactionMessage.Footer = new TextMessageContent("Test Footer");
196+
197+
var interactiveMessageContent = new InteractiveNotificationContent(
198+
channelRegistrationId,
199+
recipientList,
200+
interactionMessage
201+
);
202+
203+
SendMessageResult response = await notificationMessagesClient.SendAsync(interactiveMessageContent);
204+
Console.WriteLine($"WhatsApp CTA Message with ID {response.Receipts[0].MessageId} was successfully sent.");
205+
}
206+
```
207+
208+
### Run the code
209+
210+
To run the code:
211+
212+
#### [Visual Studio](#tab/visual-studio)
213+
1. Build your solution by pressing **Ctrl+Shift+B**.
214+
2. Run the program by pressing **Ctrl+F5**.
215+
216+
#### [.NET CLI](#tab/dotnet-cli)
217+
218+
Build and run your program.
219+
220+
```console
221+
dotnet build
222+
dotnet run
223+
```
224+
225+
---
226+
227+
## Full sample code
228+
229+
```csharp
230+
using System;
231+
using System.Collections.Generic;
232+
using System.Threading.Tasks;
233+
using Azure.Communication.Messages;
234+
using Azure.Communication.Messages.Models;
235+
236+
namespace InteractiveMessagesQuickstart
237+
{
238+
public class Program
239+
{
240+
private static Guid channelRegistrationId = new Guid("<Your Channel ID>");
241+
private static List<string> recipientList = new List<string> { "<Recipient's WhatsApp Phone Number>" };
242+
private static NotificationMessagesClient notificationMessagesClient = new NotificationMessagesClient("<Your Connection String>");
243+
244+
public static async Task Main(string[] args)
245+
{
246+
Console.WriteLine("Azure Communication Services - Send WhatsApp Interactive Messages");
247+
248+
var program = new Program();
249+
await program.SendWhatsAppListMessage();
250+
await program.SendWhatsAppReplyButtonMessage();
251+
await program.SendWhatsAppClickToActionMessage();
252+
253+
Console.WriteLine("All messages sent. Press any key to exit.");
254+
Console.ReadKey();
255+
}
256+
257+
public async Task SendWhatsAppListMessage()
258+
{
259+
var actionItemsList1 = new List<ActionGroupItem>
260+
{
261+
new ActionGroupItem("priority_express", "Priority Mail Express", "Next Day to 2 Days"),
262+
new ActionGroupItem("priority_mail", "Priority Mail", "1–3 Days")
263+
};
264+
265+
var actionItemsList2 = new List<ActionGroupItem>
266+
{
267+
new ActionGroupItem("usps_ground_advantage", "USPS Ground Advantage", "2-5 Days"),
268+
new ActionGroupItem("media_mail", "Media Mail", "2-8 Days")
269+
};
270+
271+
var groups = new List<ActionGroup>
272+
{
273+
new ActionGroup("I want it ASAP!", actionItemsList1),
274+
new ActionGroup("I can wait a bit", actionItemsList2)
275+
};
276+
277+
var actionGroupContent = new ActionGroupContent("Shipping Options", groups);
278+
279+
var interactionMessage = new InteractiveMessage(
280+
new TextMessageContent("Test Body"),
281+
new WhatsAppListActionBindings(actionGroupContent)
282+
);
283+
interactionMessage.Header = new TextMessageContent("Test Header");
284+
interactionMessage.Footer = new TextMessageContent("Test Footer");
285+
286+
var interactiveMessageContent = new InteractiveNotificationContent(
287+
channelRegistrationId,
288+
recipientList,
289+
interactionMessage
290+
);
291+
292+
SendMessageResult response = await notificationMessagesClient.SendAsync(interactiveMessageContent);
293+
Console.WriteLine($"Message with ID {response.Receipts[0].MessageId} was successfully sent.");
294+
}
295+
296+
public async Task SendWhatsAppReplyButtonMessage()
297+
{
298+
var replyButtonActionList = new List<ButtonContent>
299+
{
300+
new ButtonContent("cancel", "Cancel"),
301+
new ButtonContent("agree", "Agree")
302+
};
303+
304+
var buttonSet = new ButtonSetContent(replyButtonActionList);
305+
306+
var interactionMessage = new InteractiveMessage(
307+
new TextMessageContent("Test Body"),
308+
new WhatsAppButtonActionBindings(buttonSet)
309+
);
310+
interactionMessage.Header = new TextMessageContent("Test Header");
311+
interactionMessage.Footer = new TextMessageContent("Test Footer");
312+
313+
var interactiveMessageContent = new InteractiveNotificationContent(
314+
channelRegistrationId,
315+
recipientList,
316+
interactionMessage
317+
);
318+
319+
SendMessageResult response = await notificationMessagesClient.SendAsync(interactiveMessageContent);
320+
Console.WriteLine($"Message with ID {response.Receipts[0].MessageId} was successfully sent.");
321+
}
322+
323+
public async Task SendWhatsAppClickToActionMessage()
324+
{
325+
var urlAction = new LinkContent("Test Url", new Uri("https://example.com/audio.mp3"));
326+
327+
var interactionMessage = new InteractiveMessage(
328+
new TextMessageContent("Test Body"),
329+
new WhatsAppUrlActionBindings(urlAction)
330+
);
331+
interactionMessage.Header = new TextMessageContent("Test Header");
332+
interactionMessage.Footer = new TextMessageContent("Test Footer");
333+
334+
var interactiveMessageContent = new InteractiveNotificationContent(
335+
channelRegistrationId,
336+
recipientList,
337+
interactionMessage
338+
);
339+
340+
SendMessageResult response = await notificationMessagesClient.SendAsync(interactiveMessageContent);
341+
Console.WriteLine($"WhatsApp CTA Message with ID {response.Receipts[0].MessageId} was successfully sent.");
342+
}
343+
}
344+
}
345+
```
21346

22-
[!INCLUDE [Set up environment for .NET application](../dot-net-application-setup.md)]

0 commit comments

Comments
 (0)