Incoming Webhook Integration - "Post to Channel" parse as varible not possible

Description

I would like to be able to configure my incoming integration so that “Post to Channel” can be filled via the integration script rather than just putting a single #channel or @user. This is so that I can send Direct Messages to users of RocketChat based on what user is mentioned in the incoming webhook.

For example: If Max is added as a reviewer of code in our external app, I would like my rocketchat integration to send a Direct message to Max

Firstly, does anyone have a method or solution to do this? I could not find a method

I tried to find a workaround to do this as follows:

Create an Incoming webhook that posts to a #channel
Create an outgoing webhook that triggers on messages to this channel
This outgoing webhook will send messages to the api url = api/v1/chat.postMessage & using the script will input the @user thereby sending it via direct message

The API requires authentication that can be completed via the following headers “X-Auth-Token” & “X-User-ID”. These can be generated by sending a request to the api/v1/login url.

However i cannot seem to find a method of parsing the headers via the OutgoingJavaScript & therefore i keep running into the “status”:“error”,“message”:“You must be logged in to do this.”

So Secondly, does anyone know how I can parse the headers via the outgoing script?

I have tried in this is my script:
Class Script {
process_outgoing_request({request}) {
let newheaders =
{
“X-User-ID”:
“X-Auth-Token”:
}

              return {
                      method: 'POST'
                      headers: newheaders
                      <Message information in format>
              }
       }
  }  

}

Ok, maybe… this will solve your issue, or at least make you development easier.

When you generate a new token, it invalidates the previous one.

So instead of always generating a new token with login and password, you can create a personal access token and do it directly, without token invalidation issues, which may or may not be related to your issue.

If this doesn’t solve your problem, it would help to create a simulation environment, with payloads you would like to send for the integration webhooks.

Thanks for your help.

I believe the X-Auth-Token is the same as the Personal access token, they seem to be interchangable when testing

I have a simulation environment using postman - in postman I am able to easily assign the headers & therefore I can autheticate & the api request works & posts a message. But when attempting through the outgoing webhook I cannot attach the headers via the script

There are a really esiest way todo that.

I’m using It in outgoing web Hook, but Works in incoming web hook too

Look my post: