({
messageId,
integration,
}: {
messageId: string;
integration: channelsIntegration;
})
| 74 | } |
| 75 | |
| 76 | async 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 | |
| 131 | async function processNewThread({ |
| 132 | threadId, |
no test coverage detected