Skip to content

Commit 2947dc8

Browse files
authored
Merge pull request #295996 from Shamkh/AddAuthenticationTemplateQuickstart
Adding WhatsApp Auth template quickstart.
2 parents 87c5266 + 76a2bc3 commit 2947dc8

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

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

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,19 @@ For more information about WhatsApp requirements for templates, see the WhatsApp
6666
## Code examples
6767

6868
Follow these steps to add required code snippets to the Main function of your `Program.cs` file.
69-
- [List WhatsApp templates in Azure portal](#list-whatsapp-templates-in-azure-portal).
69+
- [List WhatsApp templates](#list-whatsapp-templates).
7070
- [Send Template message with no parameters](#send-template-message-with-no-parameters).
7171
- [Send Template message with text parameters in the body](#send-template-message-with-text-parameters-in-the-body).
7272
- [Send Template message with media parameter in the header](#send-template-message-with-media-parameter-in-the-header).
7373
- [Send Template message with location in the header](#send-template-message-with-location-in-the-header).
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,70 @@ Response<SendMessageResult> sendTemplateMessageResult4 =
569572
notificationMessagesClient.Send(templateContent4);
570573
```
571574

575+
### Send Authentication Template message
576+
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)
577+
578+
#### Example
579+
580+
`auth_sample_template` template in the Azure portal:
581+
582+
:::image type="content" source="../../media/template-messages/sample-authentication-based-template.jpeg" lightbox="../../media/template-messages/sample-authentication-based-template.jpeg" alt-text="Screen capture that shows details for the authentication-template.":::
583+
584+
The template json looks like this:
585+
586+
```json
587+
[
588+
{
589+
"type": "BODY",
590+
"text": "*{{1}}* is your verification code.",
591+
"add_security_recommendation": false,
592+
"example": {
593+
"body_text": [
594+
[
595+
"123456"
596+
]
597+
]
598+
}
599+
},
600+
{
601+
"type": "BUTTONS",
602+
"buttons": [
603+
{
604+
"type": "URL",
605+
"text": "Copy code",
606+
"url": "https://www.whatsapp.com/otp/code/?otp_type=COPY_CODE&code=otp{{1}}",
607+
"example": [
608+
"https://www.whatsapp.com/otp/code/?otp_type=COPY_CODE&code=otp123456"
609+
]
610+
}
611+
]
612+
}
613+
]
614+
```
615+
616+
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.
617+
618+
```csharp
619+
// Send auth sample template message
620+
string templateNameWithauth = "auth_sample_template";
621+
string oneTimePassword = "3516517";
622+
var messageTemplateWithAuth = new MessageTemplate(templateNameWithauth, templateLanguage);
623+
WhatsAppMessageTemplateBindings auth_bindings = new();
624+
var bodyParam2 = new MessageTemplateText(name: "code", text: oneTimePassword);
625+
var uri_to_copy = new MessageTemplateQuickAction("url") { Text = oneTimePassword };
626+
627+
auth_bindings.Body.Add(new(bodyParam2.Name));
628+
auth_bindings.Buttons.Add(new WhatsAppMessageTemplateBindingsButton(WhatsAppMessageButtonSubType.Url.ToString(), uri_to_copy.Name));
629+
messageTemplateWithAuth.Values.Add(bodyParam2);
630+
messageTemplateWithAuth.Values.Add(uri_to_copy);
631+
messageTemplateWithAuth.Bindings = auth_bindings;
632+
633+
TemplateNotificationContent templateContent5 =
634+
new TemplateNotificationContent(channelRegistrationId, recipientList, messageTemplateWithAuth);
635+
Response<SendMessageResult> sendTemplateMessageResult5 =
636+
notificationMessagesClient.Send(templateContent5);
637+
```
638+
572639
## Run the code
573640

574641
Build and run your program.
Loading

0 commit comments

Comments
 (0)