Skip to content

[Notifier][RocketChat] Unclear how to configure chatters' DSN #14133

Closed
@tambait

Description

@tambait

Not sure if I'm overseeing something or it's a bug but I can't make RocketChat bridge working with DSN format found in the documentation and current bridge implementation ROCKETCHAT_DSN=rocketchat://TOKEN@ENDPOINT?channel=CHANNEL

Current implementation is using WebHooks as integration method which expects URL in the form: rchost/hooks/hookid/token

I'm not sure where to put "hookid" part when configuring chatters' DSN and everything I tried produces an error. "HookId" is not official term used in RC documentation but it is a unique string generated when creating new (incoming) WebHook in the RC admin.

What worked for me as a quick/temporary solution, tested on a self-hosted RC instance as well as RC Cloud trial, was modifying DSN to new format and RocketChatTransportFactory and RocketChatTransport classes for this new format. (As a side note, in RC, when using WebHooks integration channel property in message is only needed if overriding value set while creating new WebHook in admin panel )

ROCKETCHAT_DSN=rocketchat://userId:token@rchost?channel=CHANNEL

In the example above I'm using "userId" because I modified transport class in a way to support both WebHook and REST API methods for sending a message where I'm assuming that default integration is via WebHooks but if path property has a value then REST API is used. By default WebHooks in RC are designed to post a message only and message is part of a JSON structure which has same format as REST API message.

ROCKETCHAT_DSN=rocketchat://userId:token@rchost/api/v1/chat.postMessage?channel=CHANNEL

RocketChatTransportFactory

$scheme = $dsn->getScheme();
$userId = $this->getUser($dsn);
$accessToken = $this->getPassword($dsn);
$path = $dsn->getPath() ?? null;
$channel = $dsn->getOption('channel');
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();

if ('rocketchat' === $scheme) {
    return (new RocketChatTransport( $userId, $accessToken, $path, $channel, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
}

RocketChatTransport

if ($this->path) {
    $response = $this->client->request(
        'POST',
        sprintf('https://%s%s', $this->getEndpoint(), $this->path),
        [
            'headers' => [
                SELF::USER_HEADER => $this->userId,
                SELF::TOKEN_HEADER => $this->accessToken,
            ],
            'json' => array_filter($options),
        ]
    );

}
else {
    $response = $this->client->request(
        'POST',
        sprintf('https://%s/hooks/%s/%s', $this->getEndpoint(), $this->userId, $this->accessToken),
        [
            'json' => array_filter($options),
        ]
    );
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions