Skip to content
AnnA Docs

Sending active notifications

This service executes template notifications and sends to the users through WhatsApp

POST variables

  • HASH: Hash of the company where the template is registered
  • ANNAEXEC: The generated IV, which will be used to encrypt the values of other variables
  • Name: The name of the template that will be executed.
  • Namespace: 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 {{IMAGE}}, {{var1}}, {{var2}}, … or image, var1, var2, …
      • PropValue: Value which will replace the macro/variable
    • 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

Examples

Some examples on how to implement the dispatch of AnnA Notifications:

  public static string Execute_WebService()
  {
    string DecKey = "DECRYPTION_KEY";
    string EncKey = "ENCRYPTION_KEY";
    string Hash = "COMPANY_HASH";
    // Generate new IV
    TripleDESCryptoServiceProvider auxTdes = new TripleDESCryptoServiceProvider();
    auxTdes.GenerateIV();
    byte[] IVArray = auxTdes.IV;
    string IV = Convert.ToBase64String(IVArray);

    string templateName = "TEMPLATE_NAME";
    string encryptedTemplateName = Encrypt(templateName, EncKey, IV);
    string templateNamespace = "TEMPLATE_NAMESPACE";
    string encryptedTemplateNamespace = Encrypt(templateNamespace, EncKey, IV);

    string json = "[{";
    json += "\"PhoneList\":\"950691561;914694745\",";
    json += "\"Prop_Keys\":";
    json += "   [";
    json += "       {";
    json += "           \"PropName\":\"var1\",";
    json += "           \"PropValue\":\"AnnA\"";
    json += "       },";
    json += "       {";
    json += "           \"PropName\":\"var2\",";
    json += "           \"PropValue\":\"10/07/2021\"";
    json += "       }";
    json += "   ],";
    json += "\"Prop_Parms\":";
    json += "   [";
    json += "       {";
    json += "           \"PropName\":\"var\",";
    json += "           \"PropValue\":\"AnnA\"";
    json += "       }";
    json += "   ]},";
    json += "   {";
    json += "\"PhoneList\":\"977225248;971195982\",";
    json += "\"Prop_Keys\":";
    json += "   [";
    json += "       {";
    json += "           \"PropName\":\"var2\",";
    json += "           \"PropValue\":\"10/08/2021\"";
    json += "       }";
    json += "   ],";
    json += "\"Prop_Parms\":";
    json += "   [";
    json += "       {";
    json += "           \"PropName\":\"var\",";
    json += "           \"PropValue\":\"AnnA\"";
    json += "       }";
    json += "   ]";
    json += "}]";

    string encryptedTemplateData = Encrypt(json, EncKey, IV);

    string postData = "HASH=" + Uri.EscapeDataString(Hash);
    postData += "&ANNAEXEC=" + Uri.EscapeDataString(IV);
    postData += "&Name=" + Uri.EscapeDataString(encryptedTemplateName);
    postData += "&Namespace=" + Uri.EscapeDataString(encryptedTemplateNamespace);
    postData += "&TemplateData=" + Uri.EscapeDataString(encryptedTemplateData);
    byte[] data = Encoding.UTF8.GetBytes(postData);

    string url = "https://YOUR_ANNA_URL/aannatemplatenotification.aspx";
    WebRequest requisicaoWeb = WebRequest.Create(url);
    requisicaoWeb.Method = "POST";
    requisicaoWeb.ContentType = "application/x-www-form-urlencoded";
    requisicaoWeb.ContentLength = data.Length;

    Stream dataStream = requisicaoWeb.GetRequestStream();

    dataStream.Write(data, 0, data.Length);
    dataStream.Close();

    WebResponse response = requisicaoWeb.GetResponse();

    using (dataStream = response.GetResponseStream())
    {
        StreamReader reader = new StreamReader(dataStream);
        string responseFromServer = reader.ReadToEnd();

        if (responseFromServer.Contains(IV))
        {
            string newEncryptedIv = responseFromServer.Substring(responseFromServer.IndexOf(IV));
            newEncryptedIv = newEncryptedIv.Replace(IV, "");
            string encryptedResponse = responseFromServer.Substring(0, responseFromServer.IndexOf(IV));

            string newIv = Decrypt(newEncryptedIv, EncKey, IV);

            string responseData = Decrypt(encryptedResponse, DecKey, newIv);

            response.Close();

            return responseData;
        }
        else
        {
            response.Close();
            return responseFromServer;
        }
    }
  }