Deveesh
Deveesh
NNovu
Created by Deveesh on 10/6/2023 in #💬│support
Adding Rocket Chat provider to Novu
Most of issues seems to be occupied... I will try to find some issues and resolve it, or wait for some new ones
20 replies
NNovu
Created by Deveesh on 10/6/2023 in #💬│support
Adding Rocket Chat provider to Novu
I will watch that video, it will give me more idea about providers.
20 replies
NNovu
Created by Deveesh on 10/6/2023 in #💬│support
Adding Rocket Chat provider to Novu
Ah shoot! It is fine... I will search for some other issues
20 replies
NNovu
Created by Deveesh on 10/6/2023 in #💬│support
Adding Rocket Chat provider to Novu
@Zac Clifton sorry to disturb. Any suggestions regarding the above code?
20 replies
NNovu
Created by Deveesh on 10/6/2023 in #💬│support
Adding Rocket Chat provider to Novu
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(),
};
}
}
20 replies
NNovu
Created by Deveesh on 10/6/2023 in #💬│support
Adding Rocket Chat provider to Novu
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?
20 replies
NNovu
Created by Deveesh on 10/6/2023 in #💬│support
Adding Rocket Chat provider to Novu
Oh I will remove it!
20 replies
NNovu
Created by Deveesh on 10/6/2023 in #💬│support
Adding Rocket Chat provider to Novu
@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...
20 replies
NNovu
Created by Deveesh on 10/6/2023 in #💬│support
Adding Rocket Chat provider to Novu
That helped a lot! Thank you... Surely, I will get back if I am stuck again...
20 replies