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

Function formatInput

apps/sim/lib/webhooks/providers/whatsapp.ts:276–368  ·  view source on GitHub ↗
({ body }: FormatInputContext)

Source from the content-addressed store, hash-verified

274 },
275
276 async formatInput({ body }: FormatInputContext): Promise<FormatInputResult> {
277 const payload = isRecord(body) ? body : undefined
278 const contacts: Array<{ wa_id?: string; profile?: { name?: string } }> = []
279 const messages: Array<{
280 messageId?: string
281 from?: string
282 phoneNumberId?: string
283 displayPhoneNumber?: string
284 text?: string
285 timestamp?: string
286 messageType?: string
287 raw: Record<string, unknown>
288 }> = []
289 const statuses: Array<{
290 messageId?: string
291 recipientId?: string
292 phoneNumberId?: string
293 displayPhoneNumber?: string
294 status?: string
295 timestamp?: string
296 conversation?: Record<string, unknown>
297 pricing?: Record<string, unknown>
298 raw: Record<string, unknown>
299 }> = []
300
301 for (const { value } of getWhatsAppChanges(body)) {
302 const metadata = isRecord(value.metadata) ? value.metadata : undefined
303
304 if (Array.isArray(value.contacts)) {
305 for (const contact of value.contacts) {
306 if (!isRecord(contact)) {
307 continue
308 }
309
310 contacts.push(normalizeWhatsAppContact(contact))
311 }
312 }
313
314 if (Array.isArray(value.messages)) {
315 for (const message of value.messages) {
316 if (!isRecord(message)) {
317 continue
318 }
319
320 messages.push(normalizeWhatsAppMessage(message, metadata))
321 }
322 }
323
324 if (Array.isArray(value.statuses)) {
325 for (const status of value.statuses) {
326 if (!isRecord(status)) {
327 continue
328 }
329
330 statuses.push(normalizeWhatsAppStatus(status, metadata))
331 }
332 }
333 }

Callers

nothing calls this directly

Calls 6

getWhatsAppChangesFunction · 0.85
normalizeWhatsAppContactFunction · 0.85
normalizeWhatsAppMessageFunction · 0.85
normalizeWhatsAppStatusFunction · 0.85
isRecordFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected