|
1 | | -import { Hono } from 'hono' |
2 | 1 | import { Handler } from 'accounts/server' |
| 2 | +import { Card, CardText } from 'chat' |
| 3 | +import { Hono } from 'hono' |
3 | 4 | import { Address, Base64, Hex } from 'ox' |
4 | 5 | import { decodeFunctionData, http } from 'viem' |
5 | 6 | import { privateKeyToAccount } from 'viem/accounts' |
6 | 7 | import { Abis } from 'viem/tempo' |
7 | 8 | import { z } from 'zod' |
8 | | -import * as DB from '#db/client.ts' |
9 | 9 | import * as Chat from '#/chat.ts' |
10 | 10 | import * as AccountLink from '#/lib/accountLink.ts' |
| 11 | +import * as hono from '#/lib/hono.ts' |
11 | 12 | import * as Nanoid from '#/lib/nanoid.ts' |
12 | 13 | import * as Tempo from '#/lib/tempo.ts' |
13 | 14 | import * as Tip from '#/lib/tip.ts' |
14 | | -import * as hono from '#/lib/hono.ts' |
| 15 | +import * as DB from '#db/client.ts' |
15 | 16 |
|
16 | 17 | export const api = new Hono<{ |
17 | 18 | Bindings: Env |
@@ -228,25 +229,30 @@ export const api = new Hono<{ |
228 | 229 | const installation = await Chat.getSlack().getInstallation(link.provider_id) |
229 | 230 | if (!installation) return |
230 | 231 |
|
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 | + ), |
248 | 255 | ) |
249 | | - if (!json.ok) throw new Error(json.error ?? 'Slack API chat.postEphemeral failed.') |
250 | 256 | })().catch((error) => { |
251 | 257 | console.error('Failed to notify Slack member after wallet connection:', error) |
252 | 258 | }), |
|
0 commit comments