Skip to content

Commit

Permalink
Fix bot participant mapping (#50)
Browse files Browse the repository at this point in the history
* feat(mappers): map app or bot

* fix(mappers): linter warning

* feat: update order
  • Loading branch information
emilio-im authored May 7, 2024
1 parent e33ff22 commit b2ff6b5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/lib/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,14 @@ export default class SlackAPI {
const foundKey = keys.find(key => this.workspaceUsers[key]?.profile?.api_app_id === bot.bot.app_id)
const user = this.workspaceUsers[foundKey] || {}

const participant = { profile: { ...bot.bot, ...(user?.profile || {}), id: bot.bot.app_id } }
const participant = {
profile: {
...(user?.profile || {}),
...bot.bot,
id: bot.bot.app_id,
}
}

this.workspaceUsers[botId] = participant
return participant
}
Expand Down
34 changes: 27 additions & 7 deletions src/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,18 +309,38 @@ export const mapMessage = (
}
}

export const mapParticipant = ({ profile }: any): Participant => profile && {
id: profile.user_id || profile.id || profile.bot_id || profile.api_app_id,
username: profile.display_name || profile.real_name || profile.name,
fullName: profile.real_name || profile.display_name,
imgURL: profile.image_192 || profile.image_72,
email: profile.email,
export const mapAppOrBot = ({ profile }: {
profile: {
name: string
display_name: string
real_name: string
id: string
icons: Record<string, string>
}
}): Participant => profile && {
id: profile.id,
username: profile.name || profile.display_name,
fullName: profile.name || profile.display_name,
imgURL: profile.icons?.image_72 || profile.icons?.image_48 || profile.icons?.image_32,
}

export const mapParticipant = ({ profile }: any): Participant => {
if (!profile) return
if (profile.app_id) return mapAppOrBot({ profile })

return {
id: profile.user_id || profile.id || profile.bot_id || profile.api_app_id,
username: profile.display_name || profile.real_name || profile.name,
fullName: profile.real_name || profile.display_name,
imgURL: profile.image_192 || profile.image_72,
email: profile.email,
}
}

export const mapCurrentUser = ({ user, team, auth }: any): CurrentUser => ({
id: auth.enterprise_id ? `${auth.enterprise_id}-${team.id}-${auth.user_id}` : auth.user_id,
fullName: user.real_name,
displayText: `${team?.name + ' - '}${user.display_name || user.real_name}`,
displayText: `${team?.name} - ${user.display_name || user.real_name}`,
imgURL: user.image_192,
})

Expand Down

0 comments on commit b2ff6b5

Please sign in to comment.