Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 23x 3x 3x 1x 1x 2x 2x 2x 2x 1x 1x 1x 1x | import { ChannelFollowEvent } from "kick-api-types/payloads";
import { DbClient } from "../prisma";
import { sendMessage } from "../functions/messages";
import { ContentfulStatusCode } from "hono/utils/http-status";
import type { KickBroadcasterAuth } from "../functions/middleware";
import type { WebhookContext } from "../app/types";
/**
* Welcomes new followers by sending a thank-you chat message on behalf of the
* broadcaster.
*/
export const followEvent = async (
event: ChannelFollowEvent,
_db: DbClient,
ctx: WebhookContext
) => {
const broadcasterAuth = ctx.get(
"kickBroadcasterAuth"
) as KickBroadcasterAuth | null;
if (!broadcasterAuth) {
console.error(
`[event:${event.eventType}:error] Broadcaster ${event.broadcaster.username}[${event.broadcaster.user_id}] is not registered.`
);
return ctx.json({ message: "Broadcaster not registered" }, { status: 404 });
}
console.log("[Follow] Broadcaster valid - sending message");
const message = `@${event.follower.username}, thank you for following ${event.broadcaster.username}'s channel.`;
const sent = await sendMessage({
broadcaster: {
name: event.broadcaster.username!,
accessToken: broadcasterAuth.accessToken,
},
message,
});
if (sent.sent) {
console.log("[Follow] Message sent");
return ctx.json(
{ message: sent.message },
{ status: sent.status as ContentfulStatusCode }
);
} else {
console.log("[Follow] Message not sent");
return ctx.json(
{ message: sent.message },
{ status: sent.status as ContentfulStatusCode }
);
}
};
|