2023-09-24 23:49:24 -06:00
|
|
|
import { env } from "env.mjs";
|
|
|
|
import type { EventType } from "@/_utils/types";
|
2023-04-20 04:20:00 -06:00
|
|
|
|
2023-07-25 12:40:00 -06:00
|
|
|
export const publishToChannel = async (
|
2023-04-20 04:20:00 -06:00
|
|
|
channel: string,
|
|
|
|
event: EventType,
|
|
|
|
message: string
|
|
|
|
) => {
|
2023-08-24 17:49:00 -06:00
|
|
|
await fetch(
|
|
|
|
`https://rest.ably.io/channels/${env.APP_ENV}-${channel}/messages`,
|
|
|
|
{
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
2023-09-24 23:49:24 -06:00
|
|
|
Authorization: `Basic ${btoa(env.ABLY_API_KEY)}`,
|
2023-08-24 17:49:00 -06:00
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
name: event,
|
|
|
|
data: message,
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
);
|
2023-04-20 04:20:00 -06:00
|
|
|
};
|