MCPcopy Create free account
hub / github.com/vercel/examples / sendGPTResponse

Function sendGPTResponse

solutions/slackbot/api/_chat.ts:12–39  ·  view source on GitHub ↗
(event: Event)

Source from the content-addressed store, hash-verified

10}
11
12export 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}

Callers 1

POSTFunction · 0.90

Calls 2

generatePromptFromThreadFunction · 0.90
getGPTResponseFunction · 0.90

Tested by

no test coverage detected