import assert from "assert"; import { RawEvent, NormalizedEvent } from "../../types"; export default (event: RawEvent): NormalizedEvent<"intercom"> => { assert(event, `Intercom:Users null event: ${event}`); assert( event.id, `Intercom:Users event is missing the required field id ${event}` ); assert( event.created_at, `Intercom:Users event is missing the required field created_at ${event}` ); // https://developers.intercom.com/intercom-api-reference/reference#section-user-object return { id: `intercom|${event.id}`, ts: event.created_at * 1000 || Date.parse(event.created_at), user_info: { source_user_id: event.id, user_id: event.user_id, name: event.name || null, email: event.email || null, ip: null, avatar: event.avatar.image_url, nickname: null, phone: event.phone, city: event.location_data.city_name, continent_code: event.location_data.continent_code, country: event.location_data.country_name, postal_code: event.location_data.postal_code, region: event.location_data.region_name, timezone: event.location_data.timezone, country_code: event.location_data.country_code, address_line1: null, address_line2: null, user_agent: null, is_employee: null, title: null, birthday: null, company: { name: null, id: null, industry: null, employee_count: null, plan: null }, // Intercom gives us this but it's complex since it's an array with more intercom ids for the relevant company created_at: event.created_at * 1000 || Date.parse(event.created_at), age: null, gender: null, website: null, custom_attributes: null }, text: (event.name && `User '${event.name}' Created`) || (event.pseudonym && `Lead '${event.pseudonym}' Converted to User`) || null, href: `https://app.intercom.io/a/apps/${event.app_id}/users/${event.id}`, is_bad: false, direction: null, source: "intercom", stream: "users" }; };