import assert from "assert"; import { RawEvent, NormalizedEvent } from "../../types"; export default (event: RawEvent): NormalizedEvent<"intercom"> => { assert(event, `Intercom:Conversations null event: ${event}`); assert( event.id, `Intercom:Conversations event is missing the required field id ${event}` ); assert( event.created_at, `Intercom:Conversations event is missing the required field created_at ${event}` ); const startedBy = event.conversation_message && event.conversation_message.user; return { id: `intercom|${event.id}`, ts: event.created_at * 1000 || Date.parse(event.created_at), user_info: { source_user_id: (event.user && event.user.id) || null, user_id: null, name: (startedBy && startedBy.name) || null, email: (startedBy && startedBy.email) || null, ip: null, avatar: null, nickname: null, phone: null, city: null, continent_code: null, country: null, postal_code: null, region: null, timezone: null, country_code: null, address_line1: null, address_line2: null, user_agent: null, is_employee: startedBy ? startedBy.type === "admin" : null, title: null, birthday: null, company: { name: null, id: null, industry: null, employee_count: null, plan: null }, created_at: null, age: null, gender: null, website: null, custom_attributes: null }, text: (event.conversation_message && event.conversation_message.body) || null, href: `https://app.intercom.io/a/apps/_/conversations/${event.id}`, is_bad: false, direction: startedBy ? startedBy.type === "admin" ? "outbound" : "inbound" : null, source: "intercom", stream: "conversations" }; };