(event: Event)
| 10 | } |
| 11 | |
| 12 | export async function sendGPTResponse(event: Event) { |
| 13 | const { channel, ts, thread_ts } = event |
| 14 | |
| 15 | try { |
| 16 | const thread = await slack.conversations.replies({ |
| 17 | channel, |
| 18 | ts: thread_ts ?? ts, |
| 19 | inclusive: true, |
| 20 | }) |
| 21 | |
| 22 | const prompts = await generatePromptFromThread(thread) |
| 23 | const gptResponse = await getGPTResponse(prompts) |
| 24 | |
| 25 | await slack.chat.postMessage({ |
| 26 | channel, |
| 27 | thread_ts: ts, |
| 28 | text: `${gptResponse.choices[0].message.content}`, |
| 29 | }) |
| 30 | } catch (error) { |
| 31 | if (error instanceof Error) { |
| 32 | await slack.chat.postMessage({ |
| 33 | channel, |
| 34 | thread_ts: ts, |
| 35 | text: `<@${process.env.SLACK_ADMIN_MEMBER_ID}> Error: ${error.message}`, |
| 36 | }) |
| 37 | } |
| 38 | } |
| 39 | } |
no test coverage detected