RocketChat / RocketChat/Rocket.Chat

URLSearchParams Error with Outgoing Webhooks

Open
#22,958 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
46.1k
Forks
13.9k
Avg merge
3d 3h
Merged PRs (30d)
130

Description

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:
  • Version of Rocket.Chat Server: 3.17.0
  • Operating System: Debian 10 (Buster)
  • Deployment Method: Docker
  • Number of Running Instances: 1
  • DB Replicaset Oplog: [not sure]
  • NodeJS Version: lsb_release -a
  • MongoDB Version: lsb_release -a
Client Setup Information
  • Desktop App or Browser Version: Affects both desktop app and browser
  • Operating System: Windows 10
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:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names the Outgoing Webhook script runtime but no source file or test. Reproduce the URLSearchParams ReferenceError with the provided snippet, then trace how webhook scripts expose runtime APIs. Done means the supported behavior for URLSearchParams is established and the Twilio-style webhook scenario is verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.