RocketChat / Rocket.Chat

The communications platform that puts data protection first.
https://rocket.chat/
Other
40.19k stars 10.41k forks source link

URLSearchParams Error with Outgoing Webhooks #22958

Open hxrsmurf opened 3 years ago

hxrsmurf commented 3 years ago

Description:

When trying to convert JSON to application/x-www-form-urlencoded with URLSearchParams in an Outgoing Web Hook.

I'm trying to use RocketChat outgoing webhook with Twilio SMS API

Here's my snippet of Outgoing Webhook

let newBody = new URLSearchParams({
    // From and To are E.164 phone number format
    'From' : '',
    'To' : '',
    'Body': text = request.data.text
})

Steps to reproduce:

  1. Create an Outgoing Webhook
  2. Create JSON array
  3. Try to use URLSearchParams to convert to urlencoded capable string
  4. Try to trigger Outgoing Webhook
  5. Receive error in Logs

Expected behavior:

I'm expecting the Outoing Webhook to work.

Actual behavior:

I receive the error below

I20210817-19:13:49.086(0) server.js:204 Integrations ➔ Outgoing WebHook.error Error running Script in the Integration Twilio-Outgoing: I20210817-19:13:49.089(0) server.js:204 Integrations ➔ Outgoing WebHook.error Stack: 

I20210817-19:13:49.091(0) server.js:204 Integrations ➔ Outgoing WebHook.error   Error: ReferenceError: URLSearchParams is not defined       at evalmachine.<anonymous>:11:33       at /app/bundle/programs/server/npm/node_modules/meteor/promise/node_modules/meteor-promise/fiber_pool.js:43:40 

Server Setup Information:

Client Setup Information

Additional context

Per this article, the workaround is to use encodeURIComponent. So, I'm not sure if URLSearchParams is supposed to be there.

var details = {
    // From and To are E.164 phone number format
    'From' : '',
    'To' :'+1' + number,
    'Body': text[1]
};

var message = [];
for (var property in details) {
    var encodedKey = encodeURIComponent(property);
    var encodedValue = encodeURIComponent(details[property]);
    message.push(encodedKey + "=" + encodedValue);
}
message = message.join("&");

Relevant logs:

yashovardhan commented 3 years ago

Hey there,

Thanks for reporting this. I'll make sure to get this checked and let you know accordingly. The process might take sometime, please bear with us!