| 120 | } |
| 121 | |
| 122 | async function processThreadUpdate({ |
| 123 | threadId, |
| 124 | integration, |
| 125 | event, |
| 126 | }: { |
| 127 | threadId: string; |
| 128 | integration: channelsIntegration; |
| 129 | event: TwoWaySyncThreadEvent; |
| 130 | }) { |
| 131 | const thread = await linenSdk.getThread({ |
| 132 | channelId: integration.channelId, |
| 133 | threadId, |
| 134 | }); |
| 135 | |
| 136 | if (!thread) { |
| 137 | return 'ThreadNotFound'; |
| 138 | } |
| 139 | |
| 140 | if (!thread.messages.length) { |
| 141 | return 'ThreadNotFound'; |
| 142 | } |
| 143 | |
| 144 | if (!thread.externalThreadId) { |
| 145 | return 'missing thread external id'; |
| 146 | } |
| 147 | |
| 148 | return await threadHandleMap[event](thread, integration); |
| 149 | } |
| 150 | |
| 151 | const integrationMap = { |
| 152 | threadUpdated: processThreadUpdate, |