I am using Power Platform Cloud Flows (similar to Logic Apps) to receive messages from WhatsApp through webhooks. I have created a "When an HTTP Request is received" trigger.
We are trying to validate the payload using the code below. The issue we are facing is that when the message type is "text", we are able to generate a valid signature. However, when the type is "media" (image, etc.), the generated signature is not valid compared to the one we received from WhatsApp.
I am calling my custom action to use the below code.
Any ideas on how to resolve this?
public static string CalculateSignature(string appSecret, string payload)
{
/*
Please note that the calculation is made on the escaped unicode version of the payload, with lower case hex digits.
If you just calculate against the decoded bytes, you will end up with a different signature.
For example, the string äöå should be escaped to \u00e4\u00f6\u00e5.
*/
using (var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(appSecret)))
{
hmac.Initialize();
byte[] hashArray = hmac.ComputeHash(Encoding.UTF8.GetBytes(payload));
var ss = BitConverter.ToString(hashArray);
return BitConverter.ToString(hashArray).Replace("-", string.Empty).ToLower();
}
}
We have attempted other samples, but no success. I would appreciate any helpful solutions.
string x = JsonConvert.SerializeObject(payload).Trim('"');
before using statement and use x in place of payload and try