Skip to content

Commit

Permalink
feat: use cloudflare workers instead of vercel
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-737 authored Jun 6, 2024
1 parent 6a1100e commit 1ebb02f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/scripts/network/sendBroadcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default (
};
}

const messageOrError = await sendMessage(messageFormat, connection.webhookURL);
const messageOrError = await sendMessage(connection.webhookURL, messageFormat);

// return the message and webhook URL to store the message in the db
return {
Expand Down
13 changes: 7 additions & 6 deletions src/scripts/network/sendMessage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { APIMessage, WebhookMessageCreateOptions } from 'discord.js';

export default async (message: WebhookMessageCreateOptions, webhookUrl: string) => {
const res = await fetch('https://interchat-networkwebhook.vercel.app/api/send', {
method: 'PUT',
type DiscordErrorFormat = { message: string; code: number };

export default async (webhookUrl: string, message: WebhookMessageCreateOptions) => {
const res = await fetch('https://api.interchat.fun/send', {
method: 'POST',
body: JSON.stringify(message),
headers: {
authorization: `${process.env.NETWORK_API_KEY}`,
Expand All @@ -11,7 +13,6 @@ export default async (message: WebhookMessageCreateOptions, webhookUrl: string)
},
});

const resBody = await res.json();

return res.status === 200 ? (resBody.result as APIMessage) : String(resBody.error);
const resBody: APIMessage | DiscordErrorFormat = await res.json();
return 'code' in resBody ? resBody.message : resBody;
};

0 comments on commit 1ebb02f

Please sign in to comment.