Skip to content

Commit f5523dc

Browse files
committed
WhatsApp Auth template sample
1 parent 1f94860 commit f5523dc

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

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

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@ Follow these steps to add required code snippets to the Main function of your `P
7474
- [Send Template message with quick reply buttons](#send-template-message-with-quick-reply-buttons).
7575
- [Send Template message with call to action buttons with dynamic link](#send-template-message-with-call-to-action-buttons-with-dynamic-link).
7676
- [Send Template message with call to action buttons with static link](#send-template-message-with-call-to-action-buttons-with-static-link).
77+
- [Send Authentication Template message](#send-authentication-template-message).
7778

78-
### List WhatsApp templates in Azure portal
79+
### List WhatsApp templates
80+
81+
List of templates can be viewed in Azure portal or In WhatsApp Manager or Using SDK. All options are listed below in detail.
7982

8083
You can view your templates in the Azure portal by going to your Azure Communication Service resource > **Advanced Messaging** > **Templates**.
8184

@@ -569,6 +572,72 @@ Response<SendMessageResult> sendTemplateMessageResult4 =
569572
notificationMessagesClient.Send(templateContent4);
570573
```
571574

575+
### Send Authentication Template message
576+
For static links, you don't need to include `MessageTemplateQuickAction` model because the WhatsApp template has a static `CallToAction` link with no input required from the user.
577+
578+
#### Example
579+
580+
`auth_sample_template` template:
581+
582+
This sample template sends authentication template message with one-time password buttons. More details can be find [here](https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-message-templates/auth-otp-template-messages)
583+
584+
:::image type="content" source="../../media/template-messages/sample-authentication-based-template.jpeg" lightbox="../../media/sample-authentication-based-template.jpeg" alt-text="Screen capture that shows details for the authentication-template.":::
585+
586+
The template json looks like this:
587+
588+
```json
589+
[
590+
{
591+
"type": "BODY",
592+
"text": "*{{1}}* is your verification code.",
593+
"add_security_recommendation": false,
594+
"example": {
595+
"body_text": [
596+
[
597+
"123456"
598+
]
599+
]
600+
}
601+
},
602+
{
603+
"type": "BUTTONS",
604+
"buttons": [
605+
{
606+
"type": "URL",
607+
"text": "Copy code",
608+
"url": "https://www.whatsapp.com/otp/code/?otp_type=COPY_CODE&code=otp{{1}}",
609+
"example": [
610+
"https://www.whatsapp.com/otp/code/?otp_type=COPY_CODE&code=otp123456"
611+
]
612+
}
613+
]
614+
}
615+
]
616+
```
617+
618+
Create one `MessageTemplateText`, one `MessageTemplateQuickAction` params. Then assemble your list of params values and your `WhatsAppMessageTemplateBindingsButton` by providing the parameters in the order that the parameters appear in the template content. The order also matters when defining your bindings' buttons.
619+
620+
```csharp
621+
// Send auth sample template message
622+
string templateNameWithauth = "auth_sample_template";
623+
string oneTimePassword = "3516517";
624+
var messageTemplateWithAuth = new MessageTemplate(templateNameWithauth, templateLanguage);
625+
WhatsAppMessageTemplateBindings auth_bindings = new();
626+
var bodyParam2 = new MessageTemplateText(name: "code", text: oneTimePassword);
627+
var uri_to_copy = new MessageTemplateQuickAction("url") { Text = oneTimePassword };
628+
629+
auth_bindings.Body.Add(new(bodyParam2.Name));
630+
auth_bindings.Buttons.Add(new WhatsAppMessageTemplateBindingsButton(WhatsAppMessageButtonSubType.Url.ToString(), uri_to_copy.Name));
631+
messageTemplateWithAuth.Values.Add(bodyParam2);
632+
messageTemplateWithAuth.Values.Add(uri_to_copy);
633+
messageTemplateWithAuth.Bindings = auth_bindings;
634+
635+
TemplateNotificationContent templateContent5 =
636+
new TemplateNotificationContent(channelRegistrationId, recipientList, messageTemplateWithAuth);
637+
Response<SendMessageResult> sendTemplateMessageResult5 =
638+
notificationMessagesClient.Send(templateContent5);
639+
```
640+
572641
## Run the code
573642

574643
Build and run your program.
Loading

0 commit comments

Comments
 (0)