UNPKG

forest-express

Version:

Official package for all Forest Express Lianas

30 lines (29 loc) 1.25 kB
"use strict"; var JSONAPISerializer = require('jsonapi-serializer').Serializer; function serializeIntercomConversation(conversation, collectionName) { if (conversation.conversation_message) { // NOTICE: Intercom API old version conversation.subject = conversation.conversation_message.subject; conversation.body = [conversation.conversation_message.body, conversation.link]; } else { // NOTICE: Intercom API v2 conversation.subject = conversation.source.subject; // NOTICE: Add all (except the first one) messages of the conversation. conversation.body = conversation.conversation_parts.conversation_parts.map(function (part) { return part.body; }); // NOTICE: Add the first message of the conversation. conversation.body.unshift(conversation.source.body); } if (conversation.assignee) { conversation.assignee = conversation.assignee.email; } var type = "".concat(collectionName, "_intercom_conversations"); return new JSONAPISerializer(type, conversation, { attributes: ['created_at', 'updated_at', 'open', 'read', 'subject', 'body', 'assignee'], keyForAttribute: function keyForAttribute(key) { return key; } }); } module.exports = serializeIntercomConversation;