({
threadId,
token,
body,
externalChannelId,
user,
messageId,
logger,
}: {
threadId: string | undefined;
token: string;
body: string;
externalChannelId: string;
user: AuthorUser | undefined;
messageId: string;
logger: Logger;
})
| 222 | } |
| 223 | |
| 224 | async function newThread({ |
| 225 | threadId, |
| 226 | token, |
| 227 | body, |
| 228 | externalChannelId, |
| 229 | user, |
| 230 | messageId, |
| 231 | logger, |
| 232 | }: { |
| 233 | threadId: string | undefined; |
| 234 | token: string; |
| 235 | body: string; |
| 236 | externalChannelId: string; |
| 237 | user: AuthorUser | undefined; |
| 238 | messageId: string; |
| 239 | logger: Logger; |
| 240 | }) { |
| 241 | const thread = await prisma.threads.findUnique({ where: { id: threadId } }); |
| 242 | if (!thread) { |
| 243 | return 'thread not found'; |
| 244 | } |
| 245 | // new thread |
| 246 | const response = await postMessage({ |
| 247 | token, |
| 248 | body, |
| 249 | externalChannelId, |
| 250 | user, |
| 251 | logger, |
| 252 | }); |
| 253 | if (response.ok && response.message && response.message.ts) { |
| 254 | await prisma.threads.update({ |
| 255 | where: { id: threadId }, |
| 256 | data: { externalThreadId: response.message.ts }, |
| 257 | }); |
| 258 | await prisma.messages.update({ |
| 259 | where: { id: messageId }, |
| 260 | data: { externalMessageId: response.message.ts }, |
| 261 | }); |
| 262 | return 'thread created'; |
| 263 | } |
| 264 | if (!response.ok && response.error === 'channel_not_found') { |
| 265 | return { slackResponse: response.error }; |
| 266 | } |
| 267 | logger.error({ response }); |
| 268 | throw response.error || 'something went wrong'; |
| 269 | } |
| 270 | |
| 271 | function isAllowToSendMessages(s: slackAuthorizations): boolean { |
| 272 | return s.scope.indexOf('chat:write') > -1; |
no test coverage detected