1
1
import htmlToMrkdwn from 'html-to-mrkdwn-ts'
2
- import { integrationLabel } from '@crowd/types'
2
+ import { integrationLabel , integrationProfileUrl } from '@crowd/types'
3
3
import { API_CONFIG } from '../../../../../../conf'
4
4
5
5
const computeEngagementLevel = ( score ) => {
@@ -49,43 +49,61 @@ const truncateText = (text: string, characters: number = 60): string => {
49
49
export const newActivityBlocks = ( activity ) => {
50
50
const display = htmlToMrkdwn ( replaceHeadline ( `${ activity . display . default } ` ) )
51
51
const reach = activity . member . reach ?. [ activity . platform ] || activity . member . reach ?. total
52
+
53
+ const { member } = activity
52
54
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 ( ' | ' ) } ` )
55
64
}
56
65
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 } >` )
58
74
}
59
75
const engagementLevel = computeEngagementLevel ( activity . member . score || activity . engagement )
60
76
if ( engagementLevel . length > 0 ) {
61
- memberProperties . push ( `*Engagement level:* ${ engagementLevel } ` )
77
+ memberProperties . push ( `*📊 Engagement level:* ${ engagementLevel } ` )
62
78
}
63
79
if ( activity . member . activeOn ) {
64
80
const platforms = activity . member . activeOn
65
81
. map ( ( platform ) => integrationLabel [ platform ] || platform )
66
82
. join ( ' | ' )
67
- memberProperties . push ( `*Active on:* ${ platforms } ` )
83
+ memberProperties . push ( `*💬 Active on:* ${ platforms } ` )
68
84
}
69
85
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
+
70
98
return {
71
99
blocks : [
72
- {
73
- type : 'section' ,
74
- text : {
75
- type : 'mrkdwn' ,
76
- text : ':satellite_antenna: *New activity*' ,
77
- } ,
78
- } ,
79
- {
80
- type : 'divider' ,
81
- } ,
82
100
{
83
101
type : 'section' ,
84
102
text : {
85
103
type : 'mrkdwn' ,
86
104
text : `*<${ API_CONFIG . frontendUrl } /members/${ activity . member . id } |${
87
105
activity . member . displayName
88
- } >* \n *${ truncateText ( display . text ) } *`,
106
+ } >* *${ truncateText ( display . text ) } *`,
89
107
} ,
90
108
...( activity . url
91
109
? {
@@ -105,37 +123,65 @@ export const newActivityBlocks = (activity) => {
105
123
}
106
124
: { } ) ,
107
125
} ,
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
+ } ,
108
144
{
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' ,
110
158
elements : [
111
159
{
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 } ` ,
114
167
} ,
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
+ : [ ] ) ,
115
183
] ,
116
184
} ,
117
185
] ,
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
- : { } ) ,
140
186
}
141
187
}
0 commit comments