pollo/app/_lib/ably.ts
2023-11-16 21:23:51 -07:00

23 lines
525 B
TypeScript

import { env } from "env.mjs";
import type { EventType } from "@/_utils/types";
export const publishToChannel = async (
channel: string,
event: EventType,
message: string
) => {
await fetch(
`https://rest.ably.io/channels/${env.APP_ENV}-${channel}/messages`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Basic ${btoa(env.ABLY_API_KEY)}`,
},
body: JSON.stringify({
name: event,
data: message,
}),
}
);
};