API Call during Outgoing Webook

Description

Utilizing an outgoing webhook to execute a isolated API Call.

Server Setup Information

  • Version of Rocket.Chat Server: latest
  • Operating System: ubuntu 20.04 LTS
  • Deployment Method: SNAP
  • Number of Running Instances: 1
  • DB Replicaset Oplog: N/A
  • NodeJS Version: 10.19.0
  • MongoDB Version: unsure
  • Proxy: CADDY
  • Firewalls involved: UFW

Any additional Information

Good afternoon, We’re trying to execute a api call within an outgoing webhook. Its likely something wrong due to my inexperience with JS but I believe I’m close to working it out.

Here’s what I have:

class Script {
prepare_outgoing_request({ request }) {
  	let user = request['data']['user_name'];
  	
  	var url = `https://companyurl.com/api/v1/chat.search`;
  	const result = HTTP('GET', url,
      params: { 
        roomId: 'ARoomID',
        searchText: 'GOT IT',
        count: 1,
      });
     console.log(result);
}

process_outgoing_response({ request, response }) {
   }
}

My goal here is to execute this webhook upon a message of “GOT IT” hitting the channel. The webhook then needs to search the channel for previous messages to edit or delete them.

I had this working to a degree, at some point it was giving me the “You must be logged in” response from the server log. But i changed something and that broke it.

It would be ideal if I could utilize “require(‘requests’)” or some other node package to simply handle authentication and so forth for me easily. But anytime I attempt to require or import a module it tells me ‘require’ is not defined, despite installing it with npm on the server.

Please let me know your thoughts, thanks!

An update: I’ve got to this point.

class Script {
prepare_outgoing_request({ request }) {
    let user = request['data']['user_name'];
    console.log(user);

  var resp = HTTP('GET', {
    url: 'https://companyurl.com/api/v1/chat.search',
    json: true,
    headers: {'X-Auth-Token': 'MyAuthToken'}
});
  
  console.log(resp);
}   
       
process_outgoing_response({ request, response }) {
    }
}

Which gives me: error: Error: url must be absolute and start with http:// or https://