import assert from "assert"; import { RawEvent, NormalizedEvent } from "../../types"; export default (event: RawEvent): NormalizedEvent<"intercom"> => { assert(event, `Intercom:ConversationParts null event: ${event}`); assert( event.id, `Intercom:ConversationParts event is missing the required field id ${event}` ); assert( event.created_at, `Intercom:ConversationParts event is missing the required field created_at ${event}` ); if (!event.id) { console.error( `Conversation Part event is missing the required field conversation_message.id: ${event}` ); } if (!event.created_at) { console.error( `Conversation Part event is missing the required field created_at: ${event}` ); } const getAuthor = event => (event.author && (event.author.name || event.author.email || "Unknown")) || "Unknown"; const getText = event => ({ comment: event.body || `Comment by '${getAuthor(event)}'`, participant_added: `'${getAuthor(event)}' Joined the Conversation` }[event.part_type] || event.body); return { id: `intercom|${event.id}`, ts: event.created_at * 1000 || Date.parse(event.created_at), user_info: { source_user_id: event.author.id || null, user_id: null, name: null, email: event.author.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: event.author.type === "admin", 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: getText(event), href: event.parent ? `https://app.intercom.io/a/apps/_/conversations/${event.parent}` : null, is_bad: false, direction: event.author.type === "admin" ? "outbound" : "inbound", source: "intercom", stream: "conversation_parts" }; };