Skip to content

Creating an authentication hash

POST variables

  • HASH: Hash of the company
  • ANNAEXEC: The generated IV, which will be used to encrypt the values of other variables
  • ACTION: The action to be executed
    • GENERATE_USER_HASH: Generates an authentication hash for the informed user (USER_ID)
    • GENERATE_USER_HASH_FORCE_USER: Create or update an user with the values from USER_ID and USER_NAME, and generates an authentication hash
    • INACTIVATE_USER: Inactivates the informed user (USER_ID)
    • MESSENGER_STRUCTURE: Returns a json providing a list of departments (alias and name) and the list of channels for each department of the company
    • MESSENGER_ALERT_COUNTER:
      • Returns a json indicating the number of request with “Open” status that are pending a response for the user specified in the variable USER_ID or by the set of values in the variables MESSENGER_UNIQUE_DOC_TYPE and MESSENGER_UNIQUE_DOC_VALUE
      • You can also filter the result by department, channel, initial date and final date using the variable MESSENGER_FILTER
    • MESSENGER_REQUESTS:
      • Returns a json with a collection of request for the user specified in the USER_ID variable or by the set of values in the MESSENGER_UNIQUE_DOC_TYPE and MESSENGER_UNIQUE_DOC_VALUE variables, containing the following data: Department, channel, request description, opening date, protocol, status (open/closed), a flag indicating if it is pending a response from the user, and a link to view the specific request.
      • You can also filter the result by department, channel, start date, end date, status (A-open, E-closed), and pendings (S/N - pending a response from the user or not) using the variable MESSENGER_FILTER
    • MESSENGER_LINK:
      • Returns a json with the link to visualize the request full content of the messaging system for the user specified in the USER_ID variable or by the set of values in the MESSENGER_UNIQUE_DOC_TYPE and MESSENGER_UNIQUE_DOC_VALUE variables
  • USER_ID: Corporate User ID
  • USER_NAME: Corporate User name
  • MESSENGER_UNIQUE_DOC_TYPE: Contains the document type for unique user identification in the messaging system. E.g.: CPF, RG, RA, etc. Must be encrypted using the generated encryption key and IV.
  • MESSENGER_UNIQUE_DOC_VALUE: Contains the document value for unique user identification in the messaging system. E.g.: 715.037.620-76. Must be encrypted using the generated encryption key and IV.
  • MESSENGER_FILTER: (OPTIONAL) Contains filters to be applied for the actions MESSENGER_ALERT_COUNTER and MESSENGER_REQUESTS. Must be encrypted using the generated encryption key and IV.
    • The JSON format should be provided as follows:
      {
      "DepartmentAlias":"CENTRALATEND",
      "ChannelAlias": "ATENDINICIAL",
      "DataIni": "01/01/2024",
      "DataFim": "01/05/2024",
      "Status": "A",
      "Pendentes": "S"
      }
  • START_SERVICE: (Optional) Defines the service to be executed when opening AnnA Chat

Examples

public string Post()
{
string companyHash = "YOUR_COMPANY_HASH";
string encryptionKey = "YOUR_CORPORATE_USER_ENCRYPTION_KEY";
string decryptionKey = "YOUR_CORPORATE_USER_DECRYPTION_KEY";
string iv = GenerateIV();
string action = "GENERATE_USER_HASH"; // GENERATE_USER_HASH || GENERATE_USER_HASH_FORCE_USER || INACTIVATE_USER
string userId = "USER_ID";
string username = "USERNAME";
string startService = "START_SERVICE";
string url = "YOUR_ANNA_URL/aannacorporateuser.aspx";
string encryptedAction = Encrypt(action, encryptionKey, iv);
string encryptedUserId = Encrypt(userId, encryptionKey, iv);
string encryptedUserName = Encrypt(username, encryptionKey, iv);
string encryptedStartService = Encrypt(startService, encryptionKey, iv);
string dadosPost = "HASH=" + Uri.EscapeDataString(companyHash);
dadosPost += "&ANNAEXEC=" + Uri.EscapeDataString(iv);
dadosPost += "&ACTION=" + Uri.EscapeDataString(encryptedAction);
dadosPost += "&USER_ID=" + Uri.EscapeUriString(encryptedUserId);
dadosPost += "&USER_NAME=" + Uri.EscapeUriString(encryptedUserName);
dadosPost += "&START_SERVICE=" + Uri.EscapeUriString(encryptedStartService);
byte[] dados = Encoding.UTF8.GetBytes(dadosPost);
var webRequest = WebRequest.Create(url);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = dados.Length;
Stream dataStream = webRequest.GetRequestStream();
dataStream.Write(dados, 0, dados.Length);
dataStream.Close();
WebResponse response = webRequest.GetResponse();
using (dataStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
if (responseFromServer.Contains(iv))
{
string novoIVEncriptado = responseFromServer.Substring(responseFromServer.IndexOf(iv));
novoIVEncriptado = novoIVEncriptado.Replace(iv, "");
string retornoEncriptado = responseFromServer.Substring(0, responseFromServer.IndexOf(iv));
string novoIV = Decrypt(novoIVEncriptado, encryptionKey, iv);
string retorno = Decrypt(retornoEncriptado, decryptionKey, novoIV);
response.Close();
return retorno;
}
else
{
response.Close();
return responseFromServer;
}
}
}