2023-04-20 04:20:00 -06:00
|
|
|
import Ably from "ably";
|
|
|
|
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:20:00 -06:00
|
|
|
const ablyRest = new Ably.Rest(env.ABLY_PRIVATE_KEY);
|
|
|
|
|
|
|
|
export const publishToChannel = (
|
2023-04-20 04:20:00 -06:00
|
|
|
channel: string,
|
|
|
|
event: EventType,
|
|
|
|
message: string
|
|
|
|
) => {
|
2023-07-25 12:20:00 -06:00
|
|
|
try {
|
|
|
|
ablyRest.channels.get(`${env.APP_ENV}-${channel}`).publish(event, message);
|
|
|
|
} catch (error) {
|
|
|
|
console.log(`❌❌❌ Failed to send message!`);
|
|
|
|
}
|
2023-04-20 04:20:00 -06:00
|
|
|
};
|