I am building Whatsapp Flows for which I need to send the data to my N8N webhook. Facebook/Whatsapp Business Manager demands the response to be in base64 String however (as you can see in the screenshot attached). What would be the quickest and best way to achieve this?
Thank you very much in advance!!!
Problem is it doesnât reach the edit fields or code node. I selected that the respond to Webhook should be the one that sends the response. Itâs because I clicked on Test webhook I guess it didnât process further.
But anyways you manually entered âokâ
How can we send the actual response of the webhook to base64.
When you click on Listening for test event, only the webhook node will be triggered. After receiving a test event, you have the option to pin data by clicking on the pin icon located in the top right corner of the webhook node. Pinning saves the data received from the webhook. Once the data is pinned, every time you click the main Test Workflow button, the workflow will use this saved (pinned) data instead of waiting for new data.
After processing the decrypted request, create a response and encrypt it before sending it back to the WhatsApp client. Encrypt the payload using the AES key received in the request and send it back as a Base64 string.
For data_api_version â3.0â you should follow below instructions to decrypt request payload:
extract payload encryption key from encrypted_aes_key field:
decode base64-encoded field content to byte array;
decrypt resulting byte array with the private key corresponding to the uploaded public key using RSA/ECB/OAEPWithSHA-256AndMGF1Padding algorithm with SHA256 as a hash function for MGF1;
as a result, youâll get a 128-bit payload encryption key.
decrypt request payload from encrypted_flow_data field:
decode base64-encoded field content to get encrypted byte array;
decrypt encrypted byte array using AES-GCM algorithm, payload encryption key and initialization vector passed in initial_vector field (which is base64-encoded as well and should be decoded first). Note that the 128-bit authentication tag for the AES-GCM algorithm is appended to the end of the encrypted array.
result of above step is UTF-8 encoded clear request payload.
For data_api_version â3.0â you should follow below instructions to encrypt the response:
encode response payload string to response byte array using UTF-8;
prepare initialization vector for response encryption by inverting all bits of the initialization vector used for request payload encryption;
encrypt response byte array using AES-GCM algorithm with the following parameters:
secret key - payload encryption key from request decryption stage;
initialization vector for response encryption from above step;
empty AAD (additional authentication data) - many libraries assume this by default, check the documentation of the library in use;
128-bit (16 byte) length for authentication tag - many libraries assume this by default, check the documentation of the library in use;
append authentication tag generated during encryption to the end of the encryption result;
encode the whole output as base64 string and send it in the HTTP response body as plain text.
Any help still appreciated. I donât even get it to actually return the encrypted response let alone if that then works and the health check doesnt return an error. @Franz
I maked it work, this is only for ping verification, later Iâll be working on handling navigation and callbacks too, but at least with tis you can publish your flow