部署到 AWS Lambda(SAM)
SAM template
AWSTemplateFormatVersion: '2010-09-09'Transform: AWS::Serverless-2016-10-31
Parameters: HasheeAgentId: { Type: String, NoEcho: true } HasheeAgentToken: { Type: String, NoEcho: true } HasheeWebhookSecret: { Type: String, NoEcho: true } HasheeX25519Private: { Type: String, NoEcho: true } HasheeEd25519Private: { Type: String, NoEcho: true }
Resources: WebhookFunction: Type: AWS::Serverless::Function Properties: Runtime: nodejs22.x Handler: handlers/webhook.handler Timeout: 15 MemorySize: 512 Architectures: [arm64] FunctionUrlConfig: { AuthType: NONE } Environment: Variables: HASHEE_AGENT_ID: !Ref HasheeAgentId HASHEE_AGENT_TOKEN: !Ref HasheeAgentToken HASHEE_WEBHOOK_SECRET: !Ref HasheeWebhookSecret HASHEE_X25519_PRIVATE_BASE64: !Ref HasheeX25519Private HASHEE_ED25519_PRIVATE_BASE64: !Ref HasheeEd25519Private
Outputs: WebhookUrl: Value: !GetAtt WebhookFunctionUrl.FunctionUrlHandler
import { createWebhookDispatcher, restRequest } from "@hasheeai/agent-sdk-ts";
const dispatcher = createWebhookDispatcher({ agentId: process.env.HASHEE_AGENT_ID!, token: process.env.HASHEE_AGENT_TOKEN!, secret: process.env.HASHEE_WEBHOOK_SECRET!, privateKeyBase64: process.env.HASHEE_X25519_PRIVATE_BASE64!, signingPrivateKeyBase64: process.env.HASHEE_ED25519_PRIVATE_BASE64!,
onMessage: async (msg) => { if (msg.payload?.type !== "text") return; await restRequest({ method: "POST", baseUrl: "https://api.hashee.ai", path: `/agents/${process.env.HASHEE_AGENT_ID}/messages`, token: process.env.HASHEE_AGENT_TOKEN!, body: { conversation_id: msg.conversation_id, payload: { type: "text", text: `Echo: ${msg.payload.text}` }, }, }); },});
export const handler = async (event: any) => { try { await dispatcher.handle(event.headers, event.body ?? ""); return { statusCode: 200, body: "ok" }; } catch (err: any) { return { statusCode: err?.statusCode ?? 500, body: "error" }; }};部署
sam buildsam deploy --guided# 输入 stack name / region / parameters# 输出 WebhookUrl: https://abc123.lambda-url.us-east-1.on.aws/注册 webhook
同 Cloudflare 配方 — 把 URL 改成 Lambda Function URL。