Skip to content

Commit ca22d91

Browse files
committed
Fix activity blocks
1 parent d7cd9cb commit ca22d91

File tree

2 files changed

+105
-65
lines changed

2 files changed

+105
-65
lines changed

backend/src/serverless/microservices/nodejs/automation/workers/slack/newActivityBlocks.ts

Lines changed: 88 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import htmlToMrkdwn from 'html-to-mrkdwn-ts'
2-
import { integrationLabel } from '@crowd/types'
2+
import { integrationLabel, integrationProfileUrl } from '@crowd/types'
33
import { API_CONFIG } from '../../../../../../conf'
44

55
const computeEngagementLevel = (score) => {
@@ -49,43 +49,61 @@ const truncateText = (text: string, characters: number = 60): string => {
4949
export const newActivityBlocks = (activity) => {
5050
const display = htmlToMrkdwn(replaceHeadline(`${activity.display.default}`))
5151
const reach = activity.member.reach?.[activity.platform] || activity.member.reach?.total
52+
53+
const { member } = activity
5254
const memberProperties = []
53-
if (activity.member.attributes.jobTitle?.default) {
54-
memberProperties.push(activity.member.attributes.jobTitle?.default)
55+
if (member.attributes.jobTitle?.default) {
56+
memberProperties.push(`*💼 Job title:* ${member.attributes.jobTitle?.default}`)
57+
}
58+
if (member.organizations.length > 0) {
59+
const orgs = member.organizations.map(
60+
(org) =>
61+
`<${`${API_CONFIG.frontendUrl}/organizations/${org.id}`}|${org.name || org.displayName}>`,
62+
)
63+
memberProperties.push(`*🏢 Organization:* ${orgs.join(' | ')}`)
5564
}
5665
if (reach > 0) {
57-
memberProperties.push(`${reach} followers`)
66+
memberProperties.push(`*👥 Reach:* ${reach} followers`)
67+
}
68+
if (member.attributes?.location?.default) {
69+
memberProperties.push(`*📍 Location:* ${member.attributes?.location?.default}`)
70+
}
71+
if (member.emails.length > 0) {
72+
const [email] = member.emails
73+
memberProperties.push(`*✉️ Email:* <mailto:${email}|${email}>`)
5874
}
5975
const engagementLevel = computeEngagementLevel(activity.member.score || activity.engagement)
6076
if (engagementLevel.length > 0) {
61-
memberProperties.push(`*Engagement level:* ${engagementLevel}`)
77+
memberProperties.push(`*📊 Engagement level:* ${engagementLevel}`)
6278
}
6379
if (activity.member.activeOn) {
6480
const platforms = activity.member.activeOn
6581
.map((platform) => integrationLabel[platform] || platform)
6682
.join(' | ')
67-
memberProperties.push(`*Active on:* ${platforms}`)
83+
memberProperties.push(`*💬 Active on:* ${platforms}`)
6884
}
6985

86+
const profiles = Object.keys(member.username)
87+
.map((p) => {
88+
const username = (member.username?.[p] || []).length > 0 ? member.username[p][0] : null
89+
const url =
90+
member.attributes?.url?.[p] || (username && integrationProfileUrl[p](username)) || null
91+
return {
92+
platform: p,
93+
url,
94+
}
95+
})
96+
.filter((p) => !!p.url)
97+
7098
return {
7199
blocks: [
72-
{
73-
type: 'section',
74-
text: {
75-
type: 'mrkdwn',
76-
text: ':satellite_antenna: *New activity*',
77-
},
78-
},
79-
{
80-
type: 'divider',
81-
},
82100
{
83101
type: 'section',
84102
text: {
85103
type: 'mrkdwn',
86104
text: `*<${API_CONFIG.frontendUrl}/members/${activity.member.id}|${
87105
activity.member.displayName
88-
}>* \n *${truncateText(display.text)}*`,
106+
}>* *${truncateText(display.text)}*`,
89107
},
90108
...(activity.url
91109
? {
@@ -105,37 +123,65 @@ export const newActivityBlocks = (activity) => {
105123
}
106124
: {}),
107125
},
126+
...(activity.title || activity.body
127+
? [
128+
{
129+
type: 'section',
130+
text: {
131+
type: 'mrkdwn',
132+
text: `>${
133+
activity.title && activity.title !== activity.display.default
134+
? `*${htmlToMrkdwn(activity.title).text}* \n `
135+
: ''
136+
}${htmlToMrkdwn(activity.body).text}`,
137+
},
138+
},
139+
]
140+
: []),
141+
{
142+
type: 'divider',
143+
},
108144
{
109-
type: 'context',
145+
type: 'section',
146+
text: {
147+
type: 'mrkdwn',
148+
text: memberProperties.join('\n'),
149+
},
150+
accessory: {
151+
type: 'image',
152+
image_url: member.attributes?.avatarUrl?.default,
153+
alt_text: 'computer thumbnail',
154+
},
155+
},
156+
{
157+
type: 'actions',
110158
elements: [
111159
{
112-
type: 'mrkdwn',
113-
text: memberProperties.join(' • '),
160+
type: 'button',
161+
text: {
162+
type: 'plain_text',
163+
text: 'View in crowd.dev',
164+
emoji: true,
165+
},
166+
url: `${API_CONFIG.frontendUrl}/members/${member.id}`,
114167
},
168+
...(profiles.length > 0
169+
? [
170+
{
171+
type: 'overflow',
172+
options: profiles.map(({ platform, url }) => ({
173+
text: {
174+
type: 'plain_text',
175+
text: `${integrationLabel[platform] ?? platform} profile`,
176+
emoji: true,
177+
},
178+
url,
179+
})),
180+
},
181+
]
182+
: []),
115183
],
116184
},
117185
],
118-
...(activity.title || activity.body
119-
? {
120-
attachments: [
121-
{
122-
color: '#eeeeee',
123-
blocks: [
124-
{
125-
type: 'section',
126-
text: {
127-
type: 'mrkdwn',
128-
text: `${
129-
activity.title && activity.title !== activity.display.default
130-
? `*${htmlToMrkdwn(activity.title).text}* \n `
131-
: ''
132-
}${htmlToMrkdwn(activity.body).text}`,
133-
},
134-
},
135-
],
136-
},
137-
],
138-
}
139-
: {}),
140186
}
141187
}

backend/src/serverless/microservices/nodejs/automation/workers/slack/newMemberBlocks.ts

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export const newMemberBlocks = (member) => {
2727
details.push(`*✉️ Email:* <mailto:${email}|${email}>`)
2828
}
2929
const profiles = Object.keys(member.username)
30-
.filter((p) => p !== platforms[0])
30+
.filter((p) => !platforms.includes(p))
3131
.map((p) => {
32-
const username = member.username?.[p].length > 0 ? member.username[p][0] : null
32+
const username = (member.username?.[p] || []).length > 0 ? member.username[p][0] : null
3333
const url =
3434
member.attributes?.url?.[p] || (username && integrationProfileUrl[p](username)) || null
3535
return {
@@ -67,27 +67,21 @@ export const newMemberBlocks = (member) => {
6767
{
6868
type: 'divider',
6969
},
70-
...(details.length > 0 || member.attributes?.avatarUrl?.default
71-
? [
72-
{
73-
type: 'section',
74-
text: {
75-
type: 'mrkdwn',
76-
text: details.length > 0 ? details.join('\n') : '\n',
77-
},
78-
accessory: member.attributes?.avatarUrl?.default
79-
? {
80-
type: 'image',
81-
image_url: member.attributes?.avatarUrl?.default,
82-
alt_text: 'computer thumbnail',
83-
}
84-
: undefined,
85-
},
86-
{
87-
type: 'divider',
88-
},
89-
]
90-
: []),
70+
{
71+
type: 'section',
72+
text: {
73+
type: 'mrkdwn',
74+
text: details.length > 0 ? details.join('\n') : '\n',
75+
},
76+
accessory: {
77+
type: 'image',
78+
image_url: member.attributes?.avatarUrl?.default,
79+
alt_text: 'computer thumbnail',
80+
},
81+
},
82+
{
83+
type: 'divider',
84+
},
9185
{
9286
type: 'actions',
9387
elements: [

0 commit comments

Comments
 (0)