Skip to content

Commit 260dfb7

Browse files
committed
add static link template
1 parent dc9de91 commit 260dfb7

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

articles/communication-services/quickstarts/advanced-messaging/whatsapp/includes/templates/template-messages-quick-reference-net.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Follow these steps to add required code snippets to the `messages-quickstart.py`
2525
- [Send Template message with location in the header](#send-template-message-with-location-in-the-header).
2626
- [Send Template message with quick reply buttons](#send-template-message-with-quick-reply-buttons).
2727
- [Send Template message with call to action buttons with dynamic link](#send-template-message-with-call-to-action-buttons-with-dynamic-link).
28+
- [Send Template message with call to action buttons with static link](#send-template-message-with-call-to-action-buttons-with-static-link).
2829

2930
### List WhatsApp templates in Azure portal
3031

@@ -438,6 +439,87 @@ purchaseFeedbackTemplate.Values.Add(urlSuffix);
438439
purchaseFeedbackTemplate.Bindings = bindings;
439440
```
440441

442+
### Send Template message with call to action buttons with static link
443+
For static link we need not to include `MessageTemplateQuickAction` model as WhatsApp template has static `CallToAction` link and no input from user is required.
444+
445+
Template definition buttons:
446+
```json
447+
{
448+
"type": "BUTTONS",
449+
"buttons": [
450+
{
451+
"type": "URL",
452+
"text": "Take Survey",
453+
"url": "https://www.example.com/{{1}}"
454+
}
455+
]
456+
}
457+
```
458+
459+
#### Example
460+
461+
`purchase_feedback_static` template:
462+
463+
This sample template adds a button with a static URL link to the message. It also uses an image in the header and a text parameter in the body.
464+
465+
:::image type="content" source="../../media/template-messages/purchase_feedback_static_link_template.png" lightbox="../../media/template-messages/purchase_feedback_static_link_template.png" alt-text="Screenshot that shows editing URL Type in the WhatsApp manager.":::
466+
467+
In this sample, the header of the template requires an image:
468+
469+
```json
470+
{
471+
"type": "HEADER",
472+
"format": "IMAGE"
473+
},
474+
```
475+
476+
The body of the template requires one text parameter:
477+
478+
```json
479+
{
480+
"type": "BODY",
481+
"text": "Hello {{1}}, \nHope you are great day!.\n Please click on given link to explore about our program.."
482+
},
483+
```
484+
485+
The template includes a dynamic URL button with one parameter:
486+
487+
```json
488+
{
489+
"type": "BUTTONS",
490+
"buttons": [
491+
{
492+
"type": "URL",
493+
"text": "Take Survey",
494+
"url": "https://www.example.com/"
495+
}
496+
]
497+
}
498+
```
499+
500+
Create one `MessageTemplateImage`, one `MessageTemplateText`. Then assemble your list of `MessageTemplateValue` and your `MessageTemplateWhatsAppBindings` by providing the parameters in the order that the parameters appear in the template content. The order also matters when defining your bindings' buttons.
501+
502+
```csharp
503+
// Send sample template sample_template
504+
string templateNameWithcta = "purchase_feedback_static";
505+
var bodyParam1 = new MessageTemplateText(name: "customer", text: "Joe");
506+
var image = new MessageTemplateImage("image", new Uri("https://aka.ms/acsicon1"));
507+
508+
WhatsAppMessageTemplateBindings cta_bindings = new();
509+
cta_bindings.Body.Add(new(bodyParam1.Name));
510+
cta_bindings.Header.Add(new(image.Name));
511+
512+
var messageTemplateWithcta = new MessageTemplate(templateNameWithcta, templateLanguage);
513+
messageTemplateWithcta.Values.Add(bodyParam1);
514+
messageTemplateWithcta.Values.Add(image);
515+
messageTemplateWithcta.Bindings = cta_bindings;
516+
517+
TemplateNotificationContent templateContent4 =
518+
new TemplateNotificationContent(channelRegistrationId, recipientList, messageTemplateWithcta);
519+
Response<SendMessageResult> sendTemplateMessageResult4 =
520+
notificationMessagesClient.Send(templateContent4);
521+
```
522+
441523
## Run the code
442524

443525
Build and run your program.
Loading

0 commit comments

Comments
 (0)