@a2hmarket/a2hmarket 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a2hmarket/a2hmarket",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "index.ts",
@@ -19,7 +19,7 @@ import { MqttTokenClient } from "./mqtt-token.js";
19
19
  import { createSendTransport } from "./mqtt-transport.js";
20
20
  import { buildEnvelope, signEnvelope } from "./protocol.js";
21
21
  import { getA2HRuntime } from "./runtime.js";
22
- import { sendFeishuCard, buildA2HNotifyCard } from "./feishu-notify.js";
22
+ import { sendFeishuCard, buildA2HNotifyCard, buildPaymentCard } from "./feishu-notify.js";
23
23
  import { recordCardPeer } from "./reply-bridge.js";
24
24
 
25
25
  // ── MQTT Send Helper ─────────────────────────────────────────────────────
@@ -182,7 +182,29 @@ export async function startAgentService(ctx: AgentServiceContext): Promise<void>
182
182
  }
183
183
 
184
184
  // ④ Custom notification: notify human about the reply
185
- notifyHumanCard("reply", event.senderId, formatted.slice(0, 500), creds.agentId, notifyLog);
185
+ // If reply contains a Stripe checkout URL, send a dedicated payment card
186
+ const paymentUrlMatch = formatted.match(/(https:\/\/checkout\.stripe\.com\S+)/);
187
+ if (paymentUrlMatch) {
188
+ const feishu = resolveFeishuConfig();
189
+ if (feishu) {
190
+ const paymentCard = buildPaymentCard({
191
+ peerId: event.senderId,
192
+ orderId: event.messageId ?? "unknown",
193
+ paymentUrl: paymentUrlMatch[1],
194
+ agentId: creds.agentId,
195
+ });
196
+ sendFeishuCard({
197
+ appId: feishu.appId,
198
+ appSecret: feishu.appSecret,
199
+ target: feishu.target,
200
+ ...paymentCard,
201
+ })
202
+ .then((msgId) => notifyLog.info(`feishu payment card sent: ${msgId}`))
203
+ .catch((err) => notifyLog.error(`feishu payment card failed: ${err.message}`));
204
+ }
205
+ } else {
206
+ notifyHumanCard("reply", event.senderId, formatted.slice(0, 500), creds.agentId, notifyLog);
207
+ }
186
208
  },
187
209
 
188
210
  onRecordError: (err) => {
@@ -114,7 +114,7 @@ export async function sendFeishuCard(params: FeishuNotifyParams): Promise<string
114
114
  * Build a standard A2H Market notification card.
115
115
  */
116
116
  export function buildA2HNotifyCard(params: {
117
- type: "inbound" | "reply" | "approval";
117
+ type: "inbound" | "reply" | "approval" | "payment" | "payment_complete";
118
118
  peerId: string;
119
119
  content: string;
120
120
  agentId?: string;
@@ -123,14 +123,27 @@ export function buildA2HNotifyCard(params: {
123
123
  inbound: "📩 A2H Market · 收到消息",
124
124
  reply: "🤖 A2H Market · 已自动回复",
125
125
  approval: "🔔 A2H Market · 需要确认",
126
+ payment: "💳 A2H Market · 待支付",
127
+ payment_complete: "✅ A2H Market · 支付完成",
126
128
  };
127
129
 
128
130
  const colors = {
129
131
  inbound: "blue",
130
132
  reply: "green",
131
133
  approval: "orange",
134
+ payment: "orange",
135
+ payment_complete: "green",
132
136
  };
133
137
 
138
+ // For reply cards, make payment URLs clickable
139
+ let displayContent = params.content;
140
+ if (params.type === "reply") {
141
+ displayContent = displayContent.replace(
142
+ /(https:\/\/checkout\.stripe\.com\S+)/g,
143
+ "[👉 点击支付]($1)",
144
+ );
145
+ }
146
+
134
147
  const elements: FeishuCardElement[] = [
135
148
  {
136
149
  tag: "markdown",
@@ -138,7 +151,7 @@ export function buildA2HNotifyCard(params: {
138
151
  },
139
152
  {
140
153
  tag: "markdown",
141
- content: params.content,
154
+ content: displayContent,
142
155
  },
143
156
  ];
144
157
 
@@ -155,3 +168,27 @@ export function buildA2HNotifyCard(params: {
155
168
  elements,
156
169
  };
157
170
  }
171
+
172
+ /**
173
+ * Build a dedicated payment card with order details and a clickable payment button.
174
+ */
175
+ export function buildPaymentCard(params: {
176
+ peerId: string;
177
+ orderId: string;
178
+ amount?: number;
179
+ currency?: string;
180
+ paymentUrl: string;
181
+ agentId?: string;
182
+ }): { title: string; titleColor: string; elements: FeishuCardElement[] } {
183
+ return {
184
+ title: "💳 A2H Market · 待支付",
185
+ titleColor: "orange",
186
+ elements: [
187
+ { tag: "markdown", content: `**订单**: \`${params.orderId}\`` },
188
+ { tag: "markdown", content: `**金额**: ${params.amount ? (params.amount / 100).toFixed(2) : "?"} ${params.currency?.toUpperCase() ?? "USD"}` },
189
+ { tag: "markdown", content: `**来自**: \`${params.peerId}\`` },
190
+ { tag: "markdown", content: `---\n**[👉 点击支付](${params.paymentUrl})**` },
191
+ ...(params.agentId ? [{ tag: "markdown", content: `\n*Agent: ${params.agentId}*` }] : []),
192
+ ],
193
+ };
194
+ }