Sending active notifications
This service executes template notifications and sends to the users through WhatsApp
JSON Properties
- hash: Hash of the company where the template is registered
- templateName: The name of the template that will be executed.
- templateNamespace: Namespace of the template that will be executed.
- templateData: Contains the phone list and information about macros/variables for the template to be executed
- DeliveryDate: (Optional) If you need to schedule the notification/template, then this field should be filled like YYYYMMDDHHMM
- Reference: (Optional) You can use this field for any notes about this notification/template dispatch
- PhoneList: Phone list separated by semicolons, e.g., “551199999999;551388888888”
- Prop_Keys: Contains the list of macros/variables that will be replaced
- PropName: Macro/Variable ID. It can be used as {{0}}, {{1}}, {{2}},…
NOTE: The slot {{0}} is reserved for media files and the value should be an URL - PropValue: Value which will replace the macro/variable
- PropName: Macro/Variable ID. It can be used as {{0}}, {{1}}, {{2}},…
- Prop_Parms: Contains the list of parameters that will be added to the service execution
- PropName: Name of the parameter that will be added
- PropValue: Value of the parameter that will be added
- ReturnMode: (Optional) Defines the type of return. If not informed, then DEFAULT will be applied
- DEFAULT: Returns a phone list with the status of each dispatch
- RESUME: Returns a JSON with data about the dispatch
- RequestStatus: Notification dispatch status
- CANCELED: All notifications cancelled
- QUEUED: Notifications not sent yet
- PROCESSED: All notifications have been sent
- PROCESSING: The system is still sending notifications
- RequestStatus: Notification dispatch status
Examples
Some examples on how to implement the dispatch of AnnA Notifications:
var httpClient = new HttpClient { BaseAddress = new Uri("YOUR_ANNA_URL") };
var result = await httpClient.PostAsJsonAsync("REST/Credentials/GetToken", new { hash = "COMPANY_HASH", user = "USER", pass = "PASSWORD" });
var tokenResponse = await result.Content.ReadFromJsonAsync<GetTokenResponse>();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResponse?.Data.Token);
var notificationsResponse = await httpClient.PostAsJsonAsync("REST/Notifications/Send", new { hash = "COMPANY_HASH", templateName = "TEMPLATE_NAME", templateNamespace = "TEMPLATE_NAMESPACE", templateData = new List<object> { new { PhoneList = "5511111111111;5522222222222", Prop_Keys = new List<object> { new { PropName = "{{1}}", PropValue = "Value 1" } }, Reference = "Test" } } });
Console.WriteLine(await notificationsResponse.Content.ReadAsStringAsync());
public class Main { public static void main(String[] args) throws IOException, InterruptedException { var httpClient = HttpClient.newHttpClient(); Gson gson = new Gson();
String environmentUri = "https://itda.com.br/anna20/";
var credentials = new HashMap<String,String>(); credentials.put("hash", "BA475308"); credentials.put("user", "5513981283143"); credentials.put("pass", "Eclipse00");
var credentialsJson = gson.toJson(credentials);
var httpRequest = HttpRequest.newBuilder() .uri(URI.create(environmentUri + "REST/Credentials/GetToken")) .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(credentialsJson)) .build();
var credentialsResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
var tokenObj = gson.fromJson(credentialsResponse.body(), GetTokenResponse.class);
var notificationRequestBody = new HashMap<String, Object>();
notificationRequestBody.put("hash", "BA475308"); notificationRequestBody.put("templateName", "checkambiente1"); notificationRequestBody.put("templateNamespace", "8251bcca_c203_4b97_9b74_d4179b9fa83e");
notificationRequestBody.put("templateData", new ArrayList<>( Arrays.asList( Map.ofEntries( Map.entry("PhoneList", "5513982051651"), Map.entry("Prop_Keys", new ArrayList<>(Arrays.asList( Map.ofEntries( Map.entry("PropName", "{{1}}"), Map.entry("Propvalue", "Guilherme Agunzo") ) ))), Map.entry("Reference", "Teste Java") ) ) ));
var getDataRequestBodyJson = gson.toJson(notificationRequestBody);
var getDataRequest = HttpRequest.newBuilder() .uri(URI.create(environmentUri + "REST/Notifications/Send")) .setHeader("Content-Type", "application/json") .setHeader("Authorization", "Bearer "+tokenObj.data.get("Token")) .POST(HttpRequest.BodyPublishers.ofString(getDataRequestBodyJson)) .build();
var getDataResponse = httpClient.send(getDataRequest, HttpResponse.BodyHandlers.ofString());
System.out.println(getDataResponse.body());
}
}
class GetTokenResponse { public String success; public String message; public HashMap<String,Object> data; }