vessels-sdk 0.4.1 → 0.5.0
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/dist/index.cjs +51 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +51 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -178,7 +178,8 @@ var Vessels = class {
|
|
|
178
178
|
type: "message.user",
|
|
179
179
|
timestamp: e.timestamp,
|
|
180
180
|
vessel,
|
|
181
|
-
message: { id: e.message?.id, content: e.message?.content ?? null }
|
|
181
|
+
message: { id: e.message?.id, content: e.message?.content ?? null },
|
|
182
|
+
context: []
|
|
182
183
|
};
|
|
183
184
|
});
|
|
184
185
|
return { ok: true, events, hasMore: data.has_more ?? false };
|
|
@@ -209,6 +210,55 @@ var Vessels = class {
|
|
|
209
210
|
return false;
|
|
210
211
|
}
|
|
211
212
|
}
|
|
213
|
+
// Verify + parse in one call. Returns a typed event or null (invalid signature or unknown type).
|
|
214
|
+
// body: raw request body string (before JSON.parse)
|
|
215
|
+
// signature: X-Vessels-Signature header value
|
|
216
|
+
// webhookSecret: the secret shown when you created the webhook endpoint in Settings
|
|
217
|
+
async parseWebhookEvent(body, signature, webhookSecret) {
|
|
218
|
+
const valid = await this.verifyWebhook(body, signature, webhookSecret);
|
|
219
|
+
if (!valid) return null;
|
|
220
|
+
try {
|
|
221
|
+
const raw = JSON.parse(body);
|
|
222
|
+
const v = raw.data?.vessel ?? {};
|
|
223
|
+
const vessel = {
|
|
224
|
+
id: v.id,
|
|
225
|
+
externalId: v.external_id ?? null,
|
|
226
|
+
title: v.title ?? null,
|
|
227
|
+
metadata: v.metadata ?? {},
|
|
228
|
+
labels: v.labels ?? []
|
|
229
|
+
};
|
|
230
|
+
if (raw.event === "interaction.response") {
|
|
231
|
+
return {
|
|
232
|
+
id: raw.data.response_id,
|
|
233
|
+
type: "interaction.response",
|
|
234
|
+
timestamp: raw.timestamp,
|
|
235
|
+
vessel,
|
|
236
|
+
messageId: raw.data.message_id,
|
|
237
|
+
interactionType: raw.data.interaction_type,
|
|
238
|
+
response: raw.data.response,
|
|
239
|
+
interactionMetadata: raw.data.metadata ?? null,
|
|
240
|
+
user: raw.data.user ?? null
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
if (raw.event === "message.user") {
|
|
244
|
+
return {
|
|
245
|
+
id: raw.data.message_id,
|
|
246
|
+
type: "message.user",
|
|
247
|
+
timestamp: raw.timestamp,
|
|
248
|
+
vessel,
|
|
249
|
+
message: { id: raw.data.message_id, content: raw.data.content ?? null },
|
|
250
|
+
context: (raw.data.context ?? []).map((m) => ({
|
|
251
|
+
source: m.source,
|
|
252
|
+
content: m.content ?? null,
|
|
253
|
+
createdAt: m.created_at
|
|
254
|
+
}))
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
return null;
|
|
258
|
+
} catch {
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
212
262
|
};
|
|
213
263
|
|
|
214
264
|
exports.AgentActivityTypes = AgentActivityTypes;
|
package/dist/index.d.cts
CHANGED
|
@@ -74,6 +74,11 @@ interface UserMessageEvent {
|
|
|
74
74
|
id: string;
|
|
75
75
|
content: string | null;
|
|
76
76
|
};
|
|
77
|
+
context: Array<{
|
|
78
|
+
source: string;
|
|
79
|
+
content: string | null;
|
|
80
|
+
createdAt: string;
|
|
81
|
+
}>;
|
|
77
82
|
}
|
|
78
83
|
type PollEvent = InteractionResponseEvent | UserMessageEvent;
|
|
79
84
|
interface PollResponse {
|
|
@@ -138,6 +143,7 @@ declare class Vessels {
|
|
|
138
143
|
}): _vessels_types.ConfirmPreviewInteraction;
|
|
139
144
|
poll(options?: PollOptions): Promise<PollResponse>;
|
|
140
145
|
verifyWebhook(body: string, signature: string, webhookSecret: string): Promise<boolean>;
|
|
146
|
+
parseWebhookEvent(body: string, signature: string, webhookSecret: string): Promise<InteractionResponseEvent | UserMessageEvent | null>;
|
|
141
147
|
}
|
|
142
148
|
|
|
143
149
|
export { AgentActivityTypes, type InteractionResponseEvent, type PollEvent, type PollOptions, type PollResponse, type PushManyResult, type PushResponse, type UserMessageEvent, type VesselContext, Vessels, VesselsAuthError, type VesselsConfig, VesselsRateLimitError, VesselsValidationError };
|
package/dist/index.d.ts
CHANGED
|
@@ -74,6 +74,11 @@ interface UserMessageEvent {
|
|
|
74
74
|
id: string;
|
|
75
75
|
content: string | null;
|
|
76
76
|
};
|
|
77
|
+
context: Array<{
|
|
78
|
+
source: string;
|
|
79
|
+
content: string | null;
|
|
80
|
+
createdAt: string;
|
|
81
|
+
}>;
|
|
77
82
|
}
|
|
78
83
|
type PollEvent = InteractionResponseEvent | UserMessageEvent;
|
|
79
84
|
interface PollResponse {
|
|
@@ -138,6 +143,7 @@ declare class Vessels {
|
|
|
138
143
|
}): _vessels_types.ConfirmPreviewInteraction;
|
|
139
144
|
poll(options?: PollOptions): Promise<PollResponse>;
|
|
140
145
|
verifyWebhook(body: string, signature: string, webhookSecret: string): Promise<boolean>;
|
|
146
|
+
parseWebhookEvent(body: string, signature: string, webhookSecret: string): Promise<InteractionResponseEvent | UserMessageEvent | null>;
|
|
141
147
|
}
|
|
142
148
|
|
|
143
149
|
export { AgentActivityTypes, type InteractionResponseEvent, type PollEvent, type PollOptions, type PollResponse, type PushManyResult, type PushResponse, type UserMessageEvent, type VesselContext, Vessels, VesselsAuthError, type VesselsConfig, VesselsRateLimitError, VesselsValidationError };
|
package/dist/index.js
CHANGED
|
@@ -176,7 +176,8 @@ var Vessels = class {
|
|
|
176
176
|
type: "message.user",
|
|
177
177
|
timestamp: e.timestamp,
|
|
178
178
|
vessel,
|
|
179
|
-
message: { id: e.message?.id, content: e.message?.content ?? null }
|
|
179
|
+
message: { id: e.message?.id, content: e.message?.content ?? null },
|
|
180
|
+
context: []
|
|
180
181
|
};
|
|
181
182
|
});
|
|
182
183
|
return { ok: true, events, hasMore: data.has_more ?? false };
|
|
@@ -207,6 +208,55 @@ var Vessels = class {
|
|
|
207
208
|
return false;
|
|
208
209
|
}
|
|
209
210
|
}
|
|
211
|
+
// Verify + parse in one call. Returns a typed event or null (invalid signature or unknown type).
|
|
212
|
+
// body: raw request body string (before JSON.parse)
|
|
213
|
+
// signature: X-Vessels-Signature header value
|
|
214
|
+
// webhookSecret: the secret shown when you created the webhook endpoint in Settings
|
|
215
|
+
async parseWebhookEvent(body, signature, webhookSecret) {
|
|
216
|
+
const valid = await this.verifyWebhook(body, signature, webhookSecret);
|
|
217
|
+
if (!valid) return null;
|
|
218
|
+
try {
|
|
219
|
+
const raw = JSON.parse(body);
|
|
220
|
+
const v = raw.data?.vessel ?? {};
|
|
221
|
+
const vessel = {
|
|
222
|
+
id: v.id,
|
|
223
|
+
externalId: v.external_id ?? null,
|
|
224
|
+
title: v.title ?? null,
|
|
225
|
+
metadata: v.metadata ?? {},
|
|
226
|
+
labels: v.labels ?? []
|
|
227
|
+
};
|
|
228
|
+
if (raw.event === "interaction.response") {
|
|
229
|
+
return {
|
|
230
|
+
id: raw.data.response_id,
|
|
231
|
+
type: "interaction.response",
|
|
232
|
+
timestamp: raw.timestamp,
|
|
233
|
+
vessel,
|
|
234
|
+
messageId: raw.data.message_id,
|
|
235
|
+
interactionType: raw.data.interaction_type,
|
|
236
|
+
response: raw.data.response,
|
|
237
|
+
interactionMetadata: raw.data.metadata ?? null,
|
|
238
|
+
user: raw.data.user ?? null
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
if (raw.event === "message.user") {
|
|
242
|
+
return {
|
|
243
|
+
id: raw.data.message_id,
|
|
244
|
+
type: "message.user",
|
|
245
|
+
timestamp: raw.timestamp,
|
|
246
|
+
vessel,
|
|
247
|
+
message: { id: raw.data.message_id, content: raw.data.content ?? null },
|
|
248
|
+
context: (raw.data.context ?? []).map((m) => ({
|
|
249
|
+
source: m.source,
|
|
250
|
+
content: m.content ?? null,
|
|
251
|
+
createdAt: m.created_at
|
|
252
|
+
}))
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
return null;
|
|
256
|
+
} catch {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
210
260
|
};
|
|
211
261
|
|
|
212
262
|
export { AgentActivityTypes, Vessels, VesselsAuthError, VesselsRateLimitError, VesselsValidationError };
|