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

Function processNewMessage

packages/integration-github/src/outbound.ts:76–129  ·  view source on GitHub ↗
({
  messageId,
  integration,
}: {
  messageId: string;
  integration: channelsIntegration;
})

Source from the content-addressed store, hash-verified

74}
75
76async function processNewMessage({
77 messageId,
78 integration,
79}: {
80 messageId: string;
81 integration: channelsIntegration;
82}) {
83 const message = await linenSdk.getMessage({
84 messageId,
85 });
86
87 if (!message) {
88 return 'MessageNotFound';
89 }
90
91 if (!message.threadId) {
92 return 'ThreadNotFound';
93 }
94
95 const thread = await linenSdk.getThread({
96 channelId: message.channelId,
97 threadId: message.threadId,
98 });
99
100 if (!thread || !thread.externalThreadId) {
101 return 'thread not found';
102 }
103
104 if (message.externalMessageId) {
105 return 'skip two-way sync due message is not from linen';
106 }
107
108 const data: messageCreateType = {
109 displayName: message.author?.displayName || 'user',
110 body: message.body,
111 integrationId: Number(integration.externalId),
112 externalThreadId: thread.externalThreadId,
113 };
114
115 const octokit = await githubApp.getInstallationOctokit(data.integrationId);
116
117 const { issueNumber, owner, repo } = Serializer.extractDataFromExternalId(
118 data.externalThreadId
119 );
120
121 const result = await octokit.rest.issues.createComment({
122 body: _buildMessage(data.body, data.displayName),
123 issue_number: issueNumber,
124 owner,
125 repo,
126 });
127
128 return `issue commented: ${result?.data?.id}`;
129}
130
131async function processNewThread({
132 threadId,

Callers 1

processGithubIntegrationFunction · 0.70

Calls 4

_buildMessageFunction · 0.85
getMessageMethod · 0.80
getThreadMethod · 0.80

Tested by

no test coverage detected