@andreprado/agentkit 0.1.0-alpha.10 → 0.1.0-alpha.11
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.
|
@@ -97,6 +97,7 @@ https://<deploy-host>/channels/chn_<id>/whatsapp/zapster/webhook?token=<ZAPSTER_
|
|
|
97
97
|
- Zapster webhook headers are origin validation, not a cryptographic body signature.
|
|
98
98
|
- Use optional `ZAPSTER_WEBHOOK_TOKEN` in the webhook URL when the endpoint should require an extra secret known only to AgentKit and Zapster.
|
|
99
99
|
- Unsupported media should be logged as skipped/unsupported without creating an agent run.
|
|
100
|
+
- AgentKit handles Zapster `message.received` envelopes with event id at `id`, message text at `data.content.text`, and contact identity at `data.sender.id`.
|
|
100
101
|
|
|
101
102
|
## Verification
|
|
102
103
|
|
package/package.json
CHANGED
|
@@ -71,16 +71,21 @@ export const zapsterWhatsappChannelAdapter: ChannelAdapter = {
|
|
|
71
71
|
},
|
|
72
72
|
normalizeInbound(input) {
|
|
73
73
|
const body = parseJsonObject(input);
|
|
74
|
-
const
|
|
74
|
+
const officialMessage = normalizeZapsterOfficialMessage(body);
|
|
75
|
+
const message = officialMessage ?? normalizeZapsterLegacyMessage(body);
|
|
75
76
|
const instanceId = input.headers.get("x-instance-id") ?? readString(body, "instance_id") ?? "default";
|
|
76
|
-
const providerEventId =
|
|
77
|
+
const providerEventId =
|
|
78
|
+
readString(body, "id") ??
|
|
79
|
+
readString(body, "event_id") ??
|
|
80
|
+
input.headers.get("x-message-id") ??
|
|
81
|
+
message.id;
|
|
77
82
|
|
|
78
83
|
if (!providerEventId) {
|
|
79
|
-
throw new AgentKitError("channel_payload_invalid", "Zapster payload is missing event_id, X-Message-ID, or message.id.");
|
|
84
|
+
throw new AgentKitError("channel_payload_invalid", "Zapster payload is missing id, event_id, X-Message-ID, or message.id.");
|
|
80
85
|
}
|
|
81
86
|
|
|
82
|
-
const contactId =
|
|
83
|
-
const messageType =
|
|
87
|
+
const contactId = message.contactId ?? "unknown";
|
|
88
|
+
const messageType = message.type ?? "unknown";
|
|
84
89
|
const base = {
|
|
85
90
|
type: "whatsapp" as const,
|
|
86
91
|
provider: "zapster" as const,
|
|
@@ -95,6 +100,7 @@ export const zapsterWhatsappChannelAdapter: ChannelAdapter = {
|
|
|
95
100
|
providerMetadata: {
|
|
96
101
|
instanceId,
|
|
97
102
|
messageType,
|
|
103
|
+
...(readString(body, "type") ? { eventType: readString(body, "type") } : {}),
|
|
98
104
|
},
|
|
99
105
|
};
|
|
100
106
|
|
|
@@ -108,7 +114,7 @@ export const zapsterWhatsappChannelAdapter: ChannelAdapter = {
|
|
|
108
114
|
];
|
|
109
115
|
}
|
|
110
116
|
|
|
111
|
-
const text =
|
|
117
|
+
const text = message.text;
|
|
112
118
|
|
|
113
119
|
if (!text) {
|
|
114
120
|
return [
|
|
@@ -128,7 +134,7 @@ export const zapsterWhatsappChannelAdapter: ChannelAdapter = {
|
|
|
128
134
|
role: "user",
|
|
129
135
|
contentType: "text",
|
|
130
136
|
content: text,
|
|
131
|
-
providerMessageId:
|
|
137
|
+
providerMessageId: message.id,
|
|
132
138
|
},
|
|
133
139
|
},
|
|
134
140
|
];
|
|
@@ -167,6 +173,41 @@ export const zapsterWhatsappChannelAdapter: ChannelAdapter = {
|
|
|
167
173
|
},
|
|
168
174
|
};
|
|
169
175
|
|
|
176
|
+
type NormalizedZapsterWebhookMessage = {
|
|
177
|
+
id?: string;
|
|
178
|
+
contactId?: string;
|
|
179
|
+
type?: string;
|
|
180
|
+
text?: string;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
function normalizeZapsterOfficialMessage(body: Record<string, unknown>): NormalizedZapsterWebhookMessage | null {
|
|
184
|
+
if (readString(body, "type") !== "message.received") {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const data = readRecord(body, "data");
|
|
189
|
+
const content = readRecord(data, "content");
|
|
190
|
+
const sender = readRecord(data, "sender");
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
id: readString(data, "id"),
|
|
194
|
+
contactId: readString(sender, "id"),
|
|
195
|
+
type: readString(data, "type"),
|
|
196
|
+
text: readString(content, "text"),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function normalizeZapsterLegacyMessage(body: Record<string, unknown>): NormalizedZapsterWebhookMessage {
|
|
201
|
+
const message = readRecord(body, "message");
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
id: readString(message, "id"),
|
|
205
|
+
contactId: readString(message, "from"),
|
|
206
|
+
type: readString(message, "type"),
|
|
207
|
+
text: readString(readRecord(message, "text"), "body"),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
170
211
|
function verifyOptionalWebhookToken(input: WebhookVerificationInput): WebhookVerificationResult {
|
|
171
212
|
const expectsToken = input.channel.secrets.includes("ZAPSTER_WEBHOOK_TOKEN");
|
|
172
213
|
|
|
@@ -27,6 +27,8 @@ agentkit channels deliveries list support-whatsapp
|
|
|
27
27
|
|
|
28
28
|
Paste the stable AgentKit webhook URL into Zapster settings. If the channel declares `ZAPSTER_WEBHOOK_TOKEN`, append `?token=<ZAPSTER_WEBHOOK_TOKEN>` to the Zapster webhook URL. Keep phone numbers redacted in logs by default.
|
|
29
29
|
|
|
30
|
+
AgentKit handles Zapster `message.received` envelopes with event id at `id`, message text at `data.content.text`, and contact identity at `data.sender.id`. Unsupported media should be logged as skipped/unsupported without creating an agent run.
|
|
31
|
+
|
|
30
32
|
Buffer rapid WhatsApp messages:
|
|
31
33
|
|
|
32
34
|
```ts
|