AnnA Active Notification
AnnA Active Notification is a resource that makes possible for you to send notifications through WhatsApp to a batch of phone numbers.
Using AnnaTemplate class
This class will provide you a simple way to send active notifications to your clients
ArrayList<AnnaNotification> notifications = new ArrayList<>();
AnnaTemplate template = new AnnaTemplate("YOUR_ANNA_ENVIRONMENT_BASE_URL", AnnaTemplateConfig.builder() .companyHash("YOURCOMPANYHASH") .encryptionKey("YOUR_TEMPLATES_ENCRYPTION_KEY") .decryptionKey("YOUR_TEMPLATES_DECRYPTION_KEY") .templateName("TEMPLATE_NAME") .templateNamespace("TEMPLATE_NAMESPACE") .notifications(notifications) .build() );
Send notifications
What you will need:
- Base URL of your AnnA environment
- Company hash
- Encryption and decryption key
- Template name
- Template namespace
- List of phone numbers
Optionally you can set:
- List with the values of variables from the template if your template has any
- List with parameters for the template if your template has any
- Delivery date when you want or need to schedule the notification
- Reference to any notes about this notification
// List of phone numbers var phoneList = new ArrayList<String>(); phoneList.add("5511111111111"); phoneList.add("5522222222222");
// List with the values of variables from the template (optional) var propKeys = new ArrayList<String>(); propKeys.add("var1"); propKeys.add("var2");
// List with parameters for the template (optional) var propParms = new ArrayList<PropParm>(); propParms.add( PropParm.builder() .alias("parm1") .value("Hello") .build() );
// Create the notification var notification = AnnaNotification.builder() .phoneList(phoneList) .propKeys(propKeys) .propParms(propParms) .DeliveryDate(LocalDateTime.of(2033, 10, 30, 12, 30)) .Reference("Any annotations you want, if you want") .build();
// Add the notification to the list ArrayList<AnnaNotification> notifications = new ArrayList<>(); notifications.add(notification);
// Configure the template AnnaTemplate template = new AnnaTemplate("YOUR_ANNA_ENVIRONMENT_BASE_URL", AnnaTemplateConfig.builder() .companyHash("YOURCOMPANYHASH") .encryptionKey("YOUR_TEMPLATES_ENCRYPTION_KEY") .decryptionKey("YOUR_TEMPLATES_DECRYPTION_KEY") .templateName("TEMPLATE_NAME") .templateNamespace("TEMPLATE_NAMESPACE") .returnMode(TemplateReturnMode.DEFAULT) .notifications(notifications) .build() );
// Send the notifications String result = template.sendNotifications();
// Display the result System.out.println(result);
Get notification data
When sending notifications with ReturnMode as RESUME, the response will be a RequestID that you can use to get the notification data.
This service will return information about the number of notifications sent, processed and processing.
What you will need:
- Base URL of your AnnA environment
- Company hash
- Encryption and decryption key
- RequestID
// Create and configure AnnA Template // Example of AnnA environment base URL: https://learning.anna.center AnnaTemplate template = new AnnaTemplate("YOUR_ANNA_ENVIRONMENT_BASE_URL", AnnaTemplateConfig.builder() .companyHash("YOURCOMPANYHASH") .encryptionKey("YOUR_TEMPLATES_ENCRYPTION_KEY") .decryptionKey("YOUR_TEMPLATES_DECRYPTION_KEY") .build() );
int requestId = 65; // RequestId from sendNotifications() reponse when ReturnMode is set to "RESUME" String response = template.getNotificationData(requestId); // JSON response with the notification data
System.out.println(response);
GetNotificationData Response
The response will be a JSON with the following structure:
{ "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" }, ] } ] }
- Possible values for base RequestStatus:
- CANCELED
- QUEUED
- PROCESSED
- PROCESSING
- Possible values for RequestResult Status:
- canceled
- waiting
- sent
- delivered
- failed