({
messageId,
token,
body,
externalChannelId,
user,
externalThreadId,
logger,
}: {
messageId: string;
token: string;
body: string;
externalChannelId: string;
user: AuthorUser | undefined;
externalThreadId: string | null;
logger: Logger;
})
| 182 | } |
| 183 | |
| 184 | async function newReply({ |
| 185 | messageId, |
| 186 | token, |
| 187 | body, |
| 188 | externalChannelId, |
| 189 | user, |
| 190 | externalThreadId, |
| 191 | logger, |
| 192 | }: { |
| 193 | messageId: string; |
| 194 | token: string; |
| 195 | body: string; |
| 196 | externalChannelId: string; |
| 197 | user: AuthorUser | undefined; |
| 198 | externalThreadId: string | null; |
| 199 | logger: Logger; |
| 200 | }) { |
| 201 | if (!externalThreadId) { |
| 202 | return 'thread external id is missing from message'; |
| 203 | } |
| 204 | // reply |
| 205 | const response = await postReply({ |
| 206 | token, |
| 207 | body, |
| 208 | externalChannelId, |
| 209 | externalThreadId, |
| 210 | user, |
| 211 | logger, |
| 212 | }); |
| 213 | if (response.ok && response.message && response.message.ts) { |
| 214 | await prisma.messages.update({ |
| 215 | where: { id: messageId }, |
| 216 | data: { externalMessageId: response.message.ts }, |
| 217 | }); |
| 218 | return 'reply sent'; |
| 219 | } |
| 220 | logger.error({ response }); |
| 221 | throw 'something went wrong'; |
| 222 | } |
| 223 | |
| 224 | async function newThread({ |
| 225 | threadId, |
no test coverage detected