Skip to content

Commit

Permalink
fix(channel-web): fix duplicated mapping error (#1770)
Browse files Browse the repository at this point in the history
* first try

* remove log

* improve
  • Loading branch information
davidvitora authored Sep 25, 2023
1 parent 80e69f5 commit 58a8ea9
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions modules/channel-web/src/backend/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,24 @@ export default class WebchatDb {
}

async createUserMapping(botId: string, visitorId: string, userId: string): Promise<UserMapping> {
const mapping = { botId, visitorId, userId }
let mapping: UserMapping | undefined = { botId, visitorId, userId }

try {
await this.knex('web_user_map').insert(mapping)
this.cacheByVisitor.set(`${botId}_${visitorId}`, mapping)

return mapping
try {
await this.knex('web_user_map').insert(mapping)
this.cacheByVisitor.set(`${botId}_${visitorId}`, mapping)
} catch (err) {
// If the mapping already exists, we return it
mapping = await this.getMappingFromUser(userId)
if (!mapping) {
throw err
}
}
} catch (err) {
this.bp.logger.error('An error occurred while creating a user mapping.', err)

return undefined
this.bp.logger.forBot(botId).error('An error occurred while creating a user mapping.', err)
}

return mapping
}

async getFeedbackInfoForMessageIds(_target: string, messageIds: string[]) {
Expand Down

0 comments on commit 58a8ea9

Please sign in to comment.