Notificações Ativas AnnA
AnnA Active Notification é um recurso que possibilita o envio de notificações via WhatsApp para um grupo de números de telefone.
Utilizando a classe AnnaTemplate
Esta classe oferecerá a você uma maneira simples de enviar notificações ativas para seus clientes.
var template = new AnnaTemplate("YOUR_ANNA_ENVIRONMENT_BASE_URL"); template.CompanyHash = "YOURCOMPANYHASH"; template.EncryptionKey = "YOUR_TEMPLATES_ENCRYPTION_KEY"; template.DecryptionKey = "YOUR_TEMPLATES_DECRYPTION_KEY"; template.TemplateName = "TEMPLATE_NAME"; template.TemplateNamespace = "TEMPLATE_NAMESPACE"; template.Notifications = new List<AnnaNotification>(); // List of notification objects that contains PhoneList, PropKeys and PropParms
ou
var template = new AnnaTemplate("YOUR_ANNA_ENVIRONMENT_BASE_URL", new AnnaTemplateConfig { CompanyHash = "YOURCOMPANYHASH", EncryptionKey = "YOUR_TEMPLATES_ENCRYPTION_KEY", DecryptionKey = "YOUR_TEMPLATES_DECRYPTION_KEY", TemplateName = "TEMPLATE_NAME", TemplateNamespace = "TEMPLATE_NAMESPACE", Notifications = new List<AnnaNotification>() // List of notification objects that contains PhoneList, PropKeys and PropParms });
Enviando notificações
O que você vai precisar:
- URL base do seu ambiente AnnA
- Hash da empresa
- Chave de criptografia e descriptografia
- Nome do template
- Namespace do template
- Lista de números de telefone
Opcionalmente, você pode definir:
- Uma URL de mídia para enviar arquivos de imagem (IMAGE, VIDEO ou DOCUMENTO)
- Lista com os valores das variáveis do template, se o seu template tiver alguma
- Lista com parâmetros para o template, se o seu template tiver algum
- Data de entrega para agendar a notificação, se desejado ou necessário
- Referência para quaisquer notas sobre esta notificação
// Create notification var notification = new AnnaNotification { PhoneList = new List<string> { "5511111111111", "5522222222222" }, // List of phonenumbers MediaUrl = "https://example.com/image.png", // Set this property if you want to send media files (IMAGE, VIDEO or DOCUMENT) PropKeys = new List<string> { "Variable 1" }, // List with the values of variables from the template PropParms = new List<PropParm> { new PropParm { Alias = "parm1", Value = "value1" }, new PropParm { Alias = "parm2", Value = "value2" } }, DeliveryDate = new DateTime(2023, 11, 02, 13, 20, 0), // Set this property if you want to schedule the notification Reference = "Any description you want (max 100 characters)" };
// Add notification to the list var notificationsList = new List<AnnaNotification> { notification };
// Create the template, set the configurations and notifications list // Example of AnnA environment base URL: https://learning.anna.center var template = new AnnaTemplate("YOUR_ANNA_ENVIRONMENT_BASE_URL", new AnnaTemplateConfig { CompanyHash = "YOURCOMPANYHASH", EncryptionKey = "YOUR_TEMPLATES_ENCRYPTION_KEY", DecryptionKey = "YOUR_TEMPLATES_DECRYPTION_KEY", TemplateName = "TEMPLATE_NAME", TemplateNamespace = "TEMPLATE_NAMESPACE", ReturnMode = TemplateReturnMode.DEFAULT, // Change to RESUME if you want information about the request instead of a phonelist when sending the notifications Notifications = notificationsList });
string response = template.SendNotifications(); // Send the notifications and returns a JSON
Como obter os dados da notificação
Ao enviar notificações com ReturnMode como RESUME, a resposta será um RequestID que você pode usar para obter os dados da notificação.
Este serviço fornecerá informações sobre o número de notificações enviadas, processadas e em processamento.
O que você vai precisar
- URL base do seu ambiente AnnA
- Hash da empresa
- Chave de criptografia e descriptografia
- RequestID
// Create and configure AnnA Template // Example of AnnA environment base URL: https://learning.anna.center var template = new AnnaTemplate("YOUR_ANNA_ENVIRONMENT_BASE_URL", new AnnaTemplateConfig { CompanyHash = "YOURCOMPANYHASH", EncryptionKey = "YOUR_TEMPLATES_ENCRYPTION_KEY", DecryptionKey = "YOUR_TEMPLATES_DECRYPTION_KEY" });
int requestId = 65; // RequestId from SendNotifications() reponse when ReturnMode is set to "RESUME" string response = template.GetNotificationData(requestId); // JSON response with the notification data
GetNotificationData - Resposta
A resposta do método GetNotificationData é uma string JSON com a seguinte estrutura:
{ "RequestId": 1, "RequestDate": "2023-06-05T16:00:00", "RequestStatus": "PROCESSED", "TotalNumberReceived": 4, "TotalNumberValid": 4, "TotalNumberSuccess": 4, "TotalNumberError": 0, "TotalNumberWaiting": 0, "TotalNumberCanceled": 0, "RequestResult": [ { "RequestSeq": 1, "RequestPhoneNumber":"111111111", "RequestStatus":"sent", "RequestMessage":"OK", "RequestSentDatetime": "2024-08-05T16:00:00", "RequestDeliveryDatetime": "2024-08-05T16:00:00", "RequestReadDatetime": "2024-08-05T16:00:00", "RequestHasButton": true, "RequestUserAnswered": true, "RequestUserAnswer": "Sim", "SentKeys": [ { "Description": "NOME", "Value": "Giuliano" } ], "SentParms": [ { "Cod": "CPF", "Value": "11111111111" }, { "Cod": "RG", "Value": "11111111-1" }, ] }, { "RequestSeq": 1, "RequestPhoneNumber": "222222222", "RequestStatus": "sent", "RequestMessage": "OK", "RequestSentDatetime": "2024-08-05T16:00:00", "RequestDeliveryDatetime": "2024-08-05T16:00:00", "RequestReadDatetime": "2024-08-05T16:00:00", "RequestHasButton": true, "RequestUserAnswered": true, "RequestUserAnswer": "Sim", "SentKeys": [ { "Description": "NOME", "Value": "Giuliano" } ], "SentParms": [ { "Cod": "CPF", "Value": "11111111111" }, { "Cod": "RG", "Value": "11111111-1" }, ] }, { "RequestSeq": 2, "RequestPhoneNumber": "333333333", "RequestStatus": "sent", "RequestMessage": "OK", "RequestSentDatetime": "2024-08-05T16:00:00", "RequestDeliveryDatetime": "2024-08-05T16:00:00", "RequestReadDatetime": "2024-08-05T16:00:00", "RequestHasButton": true, "RequestUserAnswered": true, "RequestUserAnswer": "Sim", "SentKeys": [ { "Description": "NOME", "Value": "Giuliano" } ], "SentParms": [ { "Cod": "CPF", "Value": "11111111111" }, { "Cod": "RG", "Value": "11111111-1" }, ] }, { "RequestSeq": 2, "RequestPhoneNumber": "444444444", "RequestStatus":"sent", "RequestMessage":"OK", "RequestSentDatetime": "2024-08-05T16:00:00", "RequestDeliveryDatetime": "2024-08-05T16:00:00", "RequestReadDatetime": "2024-08-05T16:00:00", "RequestHasButton": true, "RequestUserAnswered": true, "RequestUserAnswer": "Sim", "SentKeys": [ { "Description": "NOME", "Value": "Giuliano" } ], "SentParms": [ { "Cod": "CPF", "Value": "11111111111" }, { "Cod": "RG", "Value": "11111111-1" }, ] } ] }
- Valores possíveis para o RequestStatus base:
- CANCELED
- QUEUED
- PROCESSED
- PROCESSING
- Valores possíveis para o status do RequestResult:
- canceled
- waiting
- sent
- delivered
- failed