Skip to content

Commit f40a93f

Browse files
committed
refactor: message rendering
1 parent 83df422 commit f40a93f

11 files changed

Lines changed: 551 additions & 293 deletions

File tree

.github/workflows/check.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
pnpm run db:codegen
3939
pnpm run gen:types
4040
env:
41-
SECRET_KEY: MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY=
41+
SECRET_KEY: testMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY=
4242
SLACK_CLIENT_ID: ci-placeholder
4343
SLACK_CLIENT_SECRET: ci-placeholder
4444
SLACK_SIGNING_SECRET: ci-placeholder
@@ -93,6 +93,13 @@ jobs:
9393
9494
- name: Test
9595
run: pnpm test
96+
env:
97+
FEE_PAYER_PRIVATE_KEY_MAINNET: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
98+
FEE_PAYER_PRIVATE_KEY_TESTNET: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
99+
SECRET_KEY: testMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY=
100+
SLACK_CLIENT_ID: ci-placeholder
101+
SLACK_CLIENT_SECRET: ci-placeholder
102+
SLACK_SIGNING_SECRET: ci-placeholder
96103

97104
e2e:
98105
name: E2E

src/api.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import { Hono } from 'hono'
21
import { Handler } from 'accounts/server'
2+
import { Card, CardText } from 'chat'
3+
import { Hono } from 'hono'
34
import { Address, Base64, Hex } from 'ox'
45
import { decodeFunctionData, http } from 'viem'
56
import { privateKeyToAccount } from 'viem/accounts'
67
import { Abis } from 'viem/tempo'
78
import { z } from 'zod'
8-
import * as DB from '#db/client.ts'
99
import * as Chat from '#/chat.ts'
1010
import * as AccountLink from '#/lib/accountLink.ts'
11+
import * as hono from '#/lib/hono.ts'
1112
import * as Nanoid from '#/lib/nanoid.ts'
1213
import * as Tempo from '#/lib/tempo.ts'
1314
import * as Tip from '#/lib/tip.ts'
14-
import * as hono from '#/lib/hono.ts'
15+
import * as DB from '#db/client.ts'
1516

1617
export const api = new Hono<{
1718
Bindings: Env
@@ -228,25 +229,30 @@ export const api = new Hono<{
228229
const installation = await Chat.getSlack().getInstallation(link.provider_id)
229230
if (!installation) return
230231

231-
const body = new URLSearchParams()
232-
body.set('channel', link.provider_channel_id!.replace(/^slack:/, ''))
233-
body.set('text', 'Connected to Tipbot\nUse `/tip disconnect` to disconnect.')
234-
body.set('user', link.member_provider_user_id)
235-
const response = await Chat.getSlack().withBotToken(installation.botToken, () =>
236-
fetch(`${c.env.SLACK_API_URL}/chat.postEphemeral`, {
237-
body,
238-
headers: { authorization: `Bearer ${installation.botToken}` },
239-
method: 'POST',
240-
}),
241-
)
242-
const json = z.parse(
243-
z.object({
244-
error: z.string().optional(),
245-
ok: z.boolean().optional(),
246-
}),
247-
await response.json(),
232+
await Chat.getSlack().withBotToken(installation.botToken, () =>
233+
Chat.getChat()
234+
.channel(
235+
link.provider_channel_id!.startsWith('slack:')
236+
? link.provider_channel_id!
237+
: `slack:${link.provider_channel_id!}`,
238+
)
239+
.postEphemeral(
240+
link.member_provider_user_id,
241+
{
242+
card: Card({
243+
children: [
244+
CardText(
245+
'Send and receive payments in Slack.\nTry `/tip @account for coffee`.',
246+
),
247+
],
248+
title: 'Connected to Tipbot',
249+
}),
250+
fallbackText:
251+
'Connected to Tipbot\nSend and receive payments in Slack.\nTry `/tip @account for coffee`.',
252+
},
253+
{ fallbackToDM: false },
254+
),
248255
)
249-
if (!json.ok) throw new Error(json.error ?? 'Slack API chat.postEphemeral failed.')
250256
})().catch((error) => {
251257
console.error('Failed to notify Slack member after wallet connection:', error)
252258
}),

src/api.workers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ describe('/api/account/link/:token', () => {
206206
expect(response.status).toBe(200)
207207
expect(initialize).toHaveBeenCalled()
208208
await expectSlackMessage(channelId, 'Connected to Tipbot')
209-
await expectSlackMessage(channelId, 'Use `/tip disconnect` to disconnect.')
209+
await expectSlackMessage(channelId, 'Send and receive payments in Slack.')
210210
})
211211

212212
test('rejects token reuse', async () => {

0 commit comments

Comments
 (0)