MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / processNewMessage

Function processNewMessage

packages/integration-email/src/outbound.ts:38–88  ·  view source on GitHub ↗
(
  messageId: string,
  integration: any, // TODO: add types
  event: any // TODO: add types
)

Source from the content-addressed store, hash-verified

36}
37
38async function processNewMessage(
39 messageId: string,
40 integration: any, // TODO: add types
41 event: any // TODO: add types
42) {
43 const message = await linenSdk.getMessage({ messageId });
44
45 if (!message) {
46 return 'MessageNotFound';
47 }
48 if (message.externalMessageId) {
49 return 'skip two-way sync due message is not from linen';
50 }
51 if (!message.threadId) {
52 return 'thread not found';
53 }
54
55 const thread = await linenSdk.getThread({
56 threadId: message.threadId,
57 channelId: message.channelId,
58 });
59
60 if (!thread || !thread.externalThreadId) {
61 return 'ThreadNotFound';
62 }
63
64 const lastReply = await linenSdk.findMessage({
65 threadId: message.threadId,
66 channelId: message.channelId,
67 mustHave: ['externalMessageId'],
68 orderBy: 'desc',
69 sortBy: 'sentAt',
70 });
71
72 const data = {
73 from: message.author?.displayName,
74 to: thread.messages.find(Boolean)?.author?.displayName,
75 body: message.body,
76 title: thread.title,
77 channelInbox: integration.externalId,
78 ...(lastReply?.externalMessageId && {
79 lastExternalMessageId: lastReply.externalMessageId,
80 }),
81 };
82
83 const externalId = await sendMail({ event, data });
84 return await linenSdk.updateMessage({
85 messageId,
86 externalMessageId: externalId,
87 });
88}
89
90async function sendMail({
91 event,

Callers 1

processEmailIntegrationFunction · 0.70

Calls 6

sendMailFunction · 0.85
getMessageMethod · 0.80
getThreadMethod · 0.80
findMessageMethod · 0.80
updateMessageMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected