MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / notifyChannel

Function notifyChannel

apps/web/services/channels/userJoined.ts:31–63  ·  view source on GitHub ↗
(
  channel: { id: string; channelName: string },
  linenBot: users,
  displayName: string
)

Source from the content-addressed store, hash-verified

29}
30
31async function notifyChannel(
32 channel: { id: string; channelName: string },
33 linenBot: users,
34 displayName: string
35) {
36 const lastThread = await prisma.threads.findFirst({
37 select: { messages: true, id: true },
38 where: { channelId: channel.id },
39 orderBy: { sentAt: 'desc' },
40 });
41 // if last message from channel is from linen-bot, lets append the welcome for the new user
42 if (
43 lastThread &&
44 lastThread.messages.length &&
45 lastThread.messages[0].usersId === linenBot.id &&
46 lastThread.messages[0].body.startsWith('Welcome')
47 ) {
48 let body = processMessage(lastThread.messages[0].body, displayName);
49 await prisma.messages.update({
50 data: {
51 body,
52 },
53 where: { id: lastThread.messages[0].id },
54 });
55 } else {
56 // new thread will be created
57 await createThread({
58 body: `Welcome! \`${displayName}\` joined #${channel.channelName}.`,
59 channelId: channel.id,
60 linenBotId: linenBot.id,
61 });
62 }
63}
64
65export function processMessage(body: string, displayName: string) {
66 let split = body.split('`');

Callers 1

notifyChannelsFunction · 0.85

Calls 3

processMessageFunction · 0.85
createThreadFunction · 0.70
updateMethod · 0.45

Tested by

no test coverage detected