pollo/src/server/ably.ts

24 lines
531 B
TypeScript
Raw Normal View History

2023-04-20 04:20:00 -06:00
import { env } from "~/env.mjs";
2023-07-11 17:22:54 -06:00
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",
Authorization: `Basic ${btoa(env.ABLY_PRIVATE_KEY)}`,
},
body: JSON.stringify({
name: event,
data: message,
}),
}
);
2023-04-20 04:20:00 -06:00
};