MCPcopy Create free account
hub / github.com/simstudioai/sim / extractIdempotencyId

Function extractIdempotencyId

apps/sim/lib/webhooks/providers/whatsapp.ts:232–270  ·  view source on GitHub ↗
(body: unknown)

Source from the content-addressed store, hash-verified

230 },
231
232 extractIdempotencyId(body: unknown) {
233 const keys = new Set<string>()
234
235 for (const { field, value } of getWhatsAppChanges(body)) {
236 if (Array.isArray(value.messages)) {
237 for (const message of value.messages) {
238 if (!isRecord(message) || typeof message.id !== 'string') {
239 continue
240 }
241
242 keys.add(`${field ?? 'messages'}:message:${message.id}`)
243 }
244 }
245
246 if (Array.isArray(value.statuses)) {
247 for (const status of value.statuses) {
248 if (!isRecord(status) || typeof status.id !== 'string') {
249 continue
250 }
251
252 const statusValue = typeof status.status === 'string' ? status.status : ''
253 const timestamp = typeof status.timestamp === 'string' ? status.timestamp : ''
254 keys.add(`${field ?? 'messages'}:status:${status.id}:${statusValue}:${timestamp}`)
255 }
256 }
257
258 if (Array.isArray(value.groups)) {
259 for (const group of value.groups) {
260 if (!isRecord(group) || typeof group.request_id !== 'string') {
261 continue
262 }
263
264 keys.add(`${field ?? 'groups'}:group:${group.request_id}`)
265 }
266 }
267 }
268
269 return buildWhatsAppIdempotencyKey(keys)
270 },
271
272 formatSuccessResponse() {
273 return new NextResponse(null, { status: 200 })

Callers

nothing calls this directly

Calls 4

getWhatsAppChangesFunction · 0.85
isRecordFunction · 0.70
addMethod · 0.45

Tested by

no test coverage detected