N
Novuโ€ข8mo ago
Deveesh

Adding Rocket Chat provider to Novu

So I took up an issue for adding rocket-chat provider to Novu, I did the installation steps and initialzed a new provider, but now I am kinda stucked here. Issue: https://github.com/novuhq/novu/issues/4387#event-10548897288 I have installed @rocket.chat/sdk, i guess it is needed SDK, but it is for a Bot. Rocket-chat is a chat provider, I read their documentation and can't figure out what credentials I have to add to the libs/shared/src/consts/providers/credentials/provider-credentials.ts folder. I have found this setup from the website https://developer.rocket.chat/bots/creating-your-own-bot-from-scratch/develop-a-rocket.chat-sdk-bot It would be great @Zac Clifton or anyone here can help me with it because this is the first time I am taking up something like this, and I would like to learn more and finish it. Sorry If I have done any mistakes ๐Ÿ˜ข
GitHub
[NV-2967] ๐Ÿš€ Feature: Add Rocket.chat Chat Provider ยท Issue #4387 ยท ...
๐Ÿ”– Feature description Use the Rocket.chat docs to create a new chat provider while following Novu's guide to a new provider ๐ŸŽค Why is this feature needed ? more options for the community โœŒ๏ธ How ...
10 Replies
Novu_Bot
Novu_Botโ€ข8mo ago
@Deveesh, you just advanced to level 1!
ninja7
ninja7โ€ข8mo ago
.
Zac Clifton
Zac Cliftonโ€ข8mo ago
@Deveesh Sorry for the confusion, we currently do not support bots in Novu and I think I linked to the wrong documentation. My apoliges. So with rocket.chat this would work the same as discord, the user would create a subscriber that has a webhook atached to them and we would send a message via that webhook. Here is the documentation for how to send messages with webhooks and rocket.chat. https://docs.rocket.chat/use-rocket.chat/workspace-administration/integrations#incoming-webhook-script Let me know if you have any more questions, I would be happy to answer.
Integrations
Integrate tools and services to ease everyday workflows.
Deveesh
Deveeshโ€ข8mo ago
That helped a lot! Thank you... Surely, I will get back if I am stuck again... @Zac Clifton I checked the provider files for discord and slack This is what I came up with (not sure whether it's correct)
import {
ChannelTypeEnum,
IChatOptions,
IChatProvider,
ISendMessageSuccessResponse,
} from '@novu/stateless';
import axios from 'axios';

export class RocketChatChatProvider implements IChatProvider {
id = 'rocket-chat';
channelType = ChannelTypeEnum.CHAT as ChannelTypeEnum.CHAT;
private axiosInstance = axios.create();

constructor(private config) {}

async sendMessage(data: IChatOptions): Promise<ISendMessageSuccessResponse> {
// Setting the wait parameter with the URL API to respect user parameters
const url = new URL(data.webhookUrl);
url.searchParams.set('wait', 'true');
const response = await this.axiosInstance.post(url.toString(), {
content: data.content,
});

return {
id: response.data.id,
date: new Date().toISOString(),
};
}
}
import {
ChannelTypeEnum,
IChatOptions,
IChatProvider,
ISendMessageSuccessResponse,
} from '@novu/stateless';
import axios from 'axios';

export class RocketChatChatProvider implements IChatProvider {
id = 'rocket-chat';
channelType = ChannelTypeEnum.CHAT as ChannelTypeEnum.CHAT;
private axiosInstance = axios.create();

constructor(private config) {}

async sendMessage(data: IChatOptions): Promise<ISendMessageSuccessResponse> {
// Setting the wait parameter with the URL API to respect user parameters
const url = new URL(data.webhookUrl);
url.searchParams.set('wait', 'true');
const response = await this.axiosInstance.post(url.toString(), {
content: data.content,
});

return {
id: response.data.id,
date: new Date().toISOString(),
};
}
}
This is what I came up with, I have a few questions here (sorry if they are too silly) I found this in the discord documentation
// Setting the wait parameter with the URL API to respect user parameters
const url = new URL(data.webhookUrl);
url.searchParams.set('wait', 'true');
// Setting the wait parameter with the URL API to respect user parameters
const url = new URL(data.webhookUrl);
url.searchParams.set('wait', 'true');
I don't know the correct use, but it seems as some flag to wait till user sets all the parameters (Correct me if I am wrong) Also, regarding the return id, I went through the documentation of rocket-chat and also I tried logging in and running it and I never found where and what thing is getting returned from it, in discord it is id: response.data.id while in slack it is id: response.headers['x-slack-req-id']. So here I am a little stuck ๐Ÿฅฒ. The above code maybe right also, but I never know it...
Zac Clifton
Zac Cliftonโ€ข8mo ago
So I do not think you need the search params on this call. What is the raw responce when you call the webhook?
Deveesh
Deveeshโ€ข8mo ago
Oh I will remove it! So till now I was doing wrong, I was pulling docker images and doing something weird, But after a little bit more digging I set up a server in rocket-chat and created a webhook from that documentation. This is the response I got from curl while testing the webhook.
curl -v -X POST \
-H 'Content-Type: application/json' \
<url>
# Some more content here

> Host: deveesh.rocket.chat
> User-Agent: curl/8.2.1
> Accept: */*
> Content-Type: application/json
>
< HTTP/2 200
< access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept
< access-control-allow-origin: *
< cache-control: no-store
< content-type: application/json
< date: Sun, 08 Oct 2023 04:49:31 GMT
< pragma: no-cache
< vary: Accept-Encoding
< vary: Accept-Encoding
< x-content-type-options: nosniff
< x-frame-options: sameorigin
< x-instance-id: be3c4fc4-b2f4-4db7-97f5-c316b773bc4b
< x-ratelimit-limit: 10
< x-ratelimit-remaining: 9
< x-ratelimit-reset: 1696740630924
< x-xss-protection: 1
<
* Connection #0 to host deveesh.rocket.chat left intact
{"success":true}โŽ
curl -v -X POST \
-H 'Content-Type: application/json' \
<url>
# Some more content here

> Host: deveesh.rocket.chat
> User-Agent: curl/8.2.1
> Accept: */*
> Content-Type: application/json
>
< HTTP/2 200
< access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept
< access-control-allow-origin: *
< cache-control: no-store
< content-type: application/json
< date: Sun, 08 Oct 2023 04:49:31 GMT
< pragma: no-cache
< vary: Accept-Encoding
< vary: Accept-Encoding
< x-content-type-options: nosniff
< x-frame-options: sameorigin
< x-instance-id: be3c4fc4-b2f4-4db7-97f5-c316b773bc4b
< x-ratelimit-limit: 10
< x-ratelimit-remaining: 9
< x-ratelimit-reset: 1696740630924
< x-xss-protection: 1
<
* Connection #0 to host deveesh.rocket.chat left intact
{"success":true}โŽ
Is the x-instance-id the correct id for the return statement? So this is how to providers/rocket-chat/src/lib/rocket-chat.provider.ts looks after the changes
import {
ChannelTypeEnum,
IChatOptions,
IChatProvider,
ISendMessageSuccessResponse,
} from '@novu/stateless';
import axios from 'axios';

export class RocketChatChatProvider implements IChatProvider {
id = 'rocket-chat';
channelType = ChannelTypeEnum.CHAT as ChannelTypeEnum.CHAT;
private axiosInstance = axios.create();

constructor(private config) {}

async sendMessage(data: IChatOptions): Promise<ISendMessageSuccessResponse> {
const response = await this.axiosInstance.post(data.webhookUrl, {
content: data.content,
});

return {
id: response.headers['x-instance-id'],
date: new Date().toISOString(),
};
}
}
import {
ChannelTypeEnum,
IChatOptions,
IChatProvider,
ISendMessageSuccessResponse,
} from '@novu/stateless';
import axios from 'axios';

export class RocketChatChatProvider implements IChatProvider {
id = 'rocket-chat';
channelType = ChannelTypeEnum.CHAT as ChannelTypeEnum.CHAT;
private axiosInstance = axios.create();

constructor(private config) {}

async sendMessage(data: IChatOptions): Promise<ISendMessageSuccessResponse> {
const response = await this.axiosInstance.post(data.webhookUrl, {
content: data.content,
});

return {
id: response.headers['x-instance-id'],
date: new Date().toISOString(),
};
}
}
@Zac Clifton sorry to disturb. Any suggestions regarding the above code?
Pawan Jain
Pawan Jainโ€ข8mo ago
Hi @Deveesh Apologies ๐Ÿ™๐Ÿป I choose rocket chat provider for demonstration purpose in today's office hours https://www.youtube.com/watch?v=Y_2fBwFpOps I will recommend you to choose any other issue let me know if you find any other issue, I will assign to you
Deveesh
Deveeshโ€ข8mo ago
Ah shoot! It is fine... I will search for some other issues
Novu_Bot
Novu_Botโ€ข8mo ago
@Deveesh, you just advanced to level 2!
Deveesh
Deveeshโ€ข8mo ago
I will watch that video, it will give me more idea about providers. Most of issues seems to be occupied... I will try to find some issues and resolve it, or wait for some new ones