Skip to content

Commit

Permalink
fix(webhook): user article link for all searched messages
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Jan 3, 2024
1 parent dfb8cea commit 8c534f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/webhook/handlers/askingArticleSubmissionConsent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ const askingArticleSubmissionConsent: ChatbotPostbackHandler = async ({
);
}

// No need to wait for article-user link to be created
createdArticles.forEach((article) =>
UserArticleLink.createOrUpdateByUserIdAndArticleId(userId, article.id)
);

// Use first article as representative article
const articleUrl = getArticleURL(createdArticles[0].id);
const articleCreatedMsg = t`Your submission is now recorded at ${articleUrl}`;
Expand All @@ -164,6 +159,16 @@ const askingArticleSubmissionConsent: ChatbotPostbackHandler = async ({
)
);
await setMostSimilarArticlesAsCooccurrence(searchResults, userId);
// No need to wait for article-user link to be created
searchResults.forEach(({ edges }) => {
// istanbul ignore if
if (edges.length === 0) return; // All msg now in DB, should never happen

UserArticleLink.createOrUpdateByUserIdAndArticleId(
userId,
edges[0].node.id
);
});

return {
context,
Expand Down Expand Up @@ -194,6 +199,10 @@ const askingArticleSubmissionConsent: ChatbotPostbackHandler = async ({
// The user only asks for one article
//
const article = createdArticles[0];

// No need to wait for article-user link to be created
UserArticleLink.createOrUpdateByUserIdAndArticleId(userId, article.id);

const [aiReply, { allowNewReplyUpdate }] = await Promise.all([
aiReplyPromises[0],
UserSettings.findOrInsertByUserId(userId),
Expand Down
13 changes: 12 additions & 1 deletion src/webhook/handlers/askingCooccurrence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
createCooccurredSearchResultsCarouselContents,
setMostSimilarArticlesAsCooccurrence,
} from './utils';
import UserArticleLink from 'src/database/models/userArticleLink';

const inputSchema = z.enum([POSTBACK_NO, POSTBACK_YES]);

Expand Down Expand Up @@ -171,9 +172,19 @@ const askingCooccurence: ChatbotPostbackHandler = async ({
// All messages in DB and thus can be set as cooccurrence.
await setMostSimilarArticlesAsCooccurrence(searchResults, userId);

// No need to wait for article-user link to be created
searchResults.forEach(({ edges }) => {
// istanbul ignore if
if (edges.length === 0) return; // All msg now in DB, should never happen

UserArticleLink.createOrUpdateByUserIdAndArticleId(
userId,
edges[0].node.id
);
});

// Get first few search results for each message, and make at most 10 options
//

return {
context,
replies: [
Expand Down

0 comments on commit 8c534f4

Please sign in to comment.