Skip to content

Commit 26c9b1d

Browse files
authored
fix: slack message structure to two columns and include budget property (#2942)
1 parent 6afea86 commit 26c9b1d

File tree

3 files changed

+58
-59
lines changed

3 files changed

+58
-59
lines changed

__tests__/workers/postBoostActionSlack.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,31 +81,29 @@ describe('postBoostActionSlack worker', () => {
8181
},
8282
{
8383
type: 'section',
84-
text: {
85-
type: 'mrkdwn',
86-
text: '*Post:*\n<http://localhost:5002/posts/p1|p1>',
87-
},
88-
},
89-
{
90-
type: 'section',
91-
text: {
92-
type: 'mrkdwn',
93-
text: '*Boosted by:*\n<https://app.daily.dev/1|1>',
94-
},
84+
fields: [
85+
{
86+
type: 'mrkdwn',
87+
text: '*Post:*\n<http://localhost:5002/posts/p1|p1>',
88+
},
89+
{
90+
type: 'mrkdwn',
91+
text: '*Boosted by:*\n<https://app.daily.dev/1|1>',
92+
},
93+
],
9594
},
9695
{
9796
type: 'section',
98-
text: {
99-
type: 'mrkdwn',
100-
text: '*Budget:*\n1000 :cores:',
101-
},
102-
},
103-
{
104-
type: 'section',
105-
text: {
106-
type: 'mrkdwn',
107-
text: '*Duration:*\n1',
108-
},
97+
fields: [
98+
{
99+
type: 'mrkdwn',
100+
text: '*Budget:*\n1000 :cores:',
101+
},
102+
{
103+
type: 'mrkdwn',
104+
text: '*Duration:*\n1 day',
105+
},
106+
],
109107
},
110108
{
111109
type: 'section',

src/common/slack.ts

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export const notifyNewPostBoostedSlack = async ({
4242
campaign,
4343
userId,
4444
}: NotifyBoostedPostProps): Promise<void> => {
45+
const difference = getAbsoluteDifferenceInDays(
46+
debeziumTimeToDate(campaign.endedAt),
47+
debeziumTimeToDate(campaign.startedAt),
48+
);
49+
4550
await webhooks.ads.send({
4651
blocks: [
4752
{
@@ -54,46 +59,41 @@ export const notifyNewPostBoostedSlack = async ({
5459
},
5560
{
5661
type: 'section',
57-
text: {
58-
type: 'mrkdwn',
59-
text: concatTextToNewline(
60-
'*Post:*',
61-
`<${getDiscussionLink(post.id)}|${post.id}>`,
62-
),
63-
},
64-
},
65-
{
66-
type: 'section',
67-
text: {
68-
type: 'mrkdwn',
69-
text: concatTextToNewline(
70-
'*Boosted by:*',
71-
`<https://app.daily.dev/${userId}|${userId}>`,
72-
),
73-
},
74-
},
75-
{
76-
type: 'section',
77-
text: {
78-
type: 'mrkdwn',
79-
text: concatTextToNewline(
80-
'*Budget:*',
81-
`${Math.floor(usdToCores(parseFloat(campaign.budget)))} :cores:`,
82-
),
83-
},
62+
fields: [
63+
{
64+
type: 'mrkdwn',
65+
text: concatTextToNewline(
66+
'*Post:*',
67+
`<${getDiscussionLink(post.id)}|${post.id}>`,
68+
),
69+
},
70+
{
71+
type: 'mrkdwn',
72+
text: concatTextToNewline(
73+
'*Boosted by:*',
74+
`<https://app.daily.dev/${userId}|${userId}>`,
75+
),
76+
},
77+
],
8478
},
8579
{
8680
type: 'section',
87-
text: {
88-
type: 'mrkdwn',
89-
text: concatTextToNewline(
90-
'*Duration:*',
91-
getAbsoluteDifferenceInDays(
92-
debeziumTimeToDate(campaign.endedAt),
93-
debeziumTimeToDate(campaign.startedAt),
94-
).toString(),
95-
),
96-
},
81+
fields: [
82+
{
83+
type: 'mrkdwn',
84+
text: concatTextToNewline(
85+
'*Budget:*',
86+
`${usdToCores(parseFloat(campaign.budget))} :cores:`,
87+
),
88+
},
89+
{
90+
type: 'mrkdwn',
91+
text: concatTextToNewline(
92+
'*Duration:*',
93+
`${difference} day${difference === 1 ? '' : 's'}`,
94+
),
95+
},
96+
],
9797
},
9898
{
9999
type: 'section',

src/schema/posts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,7 @@ export const typeDefs = /* GraphQL */ `
919919
postId: String!
920920
status: String!
921921
spend: Int!
922+
budget: Int!
922923
startedAt: DateTime!
923924
endedAt: DateTime
924925
impressions: Int!

0 commit comments

Comments
 (0)