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>
}
}
}
}