Skip to content

Commit

Permalink
fix: better assistant error handling for older threads (#3770)
Browse files Browse the repository at this point in the history
  • Loading branch information
SiTaggart authored Feb 12, 2024
1 parent 096ac24 commit 6e2ecb5
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions packages/paste-website/src/pages/api/paste-assistant-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,30 +147,36 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
.select("slack_thread_ts")
.eq("openai_thread_id", threadId);

if (slackThreadIDError) {
if (slackThreadIDError || slackThreadID == null) {
logger.error(`${LOG_PREFIX} Error getting slack thread ID for the message thread being updated`, {
slackThreadIDError,
});
} else {
// Post that new message to the correct slack thread for this assistant thread
const postToSlackResponse = await fetch(`${protocol}://${host}/api/post-to-slack`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
message: `New message was added to the thread: \n\n --- \n\n${message}`,
channelID: slackChannelID,
threadID: slackThreadID,
}),
});
const slackResponseJSON = await postToSlackResponse.json();
const slackResult = slackResponseJSON.result as ChatPostMessageResponse;

logger.info(`${LOG_PREFIX} Posted to slack`, {
slackMessageCreated: slackResult.ts,
message: slackResult.message?.text,
});
try {
// Post that new message to the correct slack thread for this assistant thread
const postToSlackResponse = await fetch(`${protocol}://${host}/api/post-to-slack`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
message: `New message was added to the thread: \n\n --- \n\n${message}`,
channelID: slackChannelID,
threadID: slackThreadID,
}),
});
const slackResponseJSON = await postToSlackResponse.json();
const slackResult = slackResponseJSON.result as ChatPostMessageResponse;

logger.info(`${LOG_PREFIX} Posted to slack`, {
slackMessageCreated: slackResult.ts,
message: slackResult.message?.text,
});
} catch (error) {
logger.error(`${LOG_PREFIX} Error sending slack message for thread being updated`, {
error,
});
}
}

/**
Expand Down

0 comments on commit 6e2ecb5

Please sign in to comment.