From f5be08dd897508371e4ecefc1ab2cdc4ff875d01 Mon Sep 17 00:00:00 2001 From: Katie Adee Date: Thu, 16 Aug 2018 10:43:57 -0400 Subject: [PATCH] feat(app): Add robot name to intercom on connect (#2069) --- app/src/support.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/support.js b/app/src/support.js index 971241dce79..85a39b88010 100644 --- a/app/src/support.js +++ b/app/src/support.js @@ -1,7 +1,6 @@ // @flow // user support module import noop from 'lodash/noop' -import {LOCATION_CHANGE} from 'react-router-redux' import {version} from './../package.json' import createLogger from './logger' @@ -18,6 +17,7 @@ const INTERCOM_ID = process.env.OT_APP_INTERCOM_ID // intercom handler (default noop) let intercom = noop +let userId export function initializeSupport (): ThunkAction { return (_, getState) => { @@ -29,21 +29,26 @@ export function initializeSupport (): ThunkAction { } export const supportMiddleware: Middleware = (store) => (next) => (action) => { - // update intercom on page change - // TODO(mc, 2018-08-02): this is likely to hit intercom throttle limit - if (action.type === LOCATION_CHANGE) intercom('update') + if (action.type === 'robot:CONNECT_RESPONSE') { + const state = store.getState() + const robot = state.robot.connection.connectRequest.name + const data = {user_id: userId, 'Robot Name': robot} + log.debug('Updating intercom data', {data}) + intercom('update', {data}) + } return next(action) } function initializeIntercom (config: SupportConfig) { if (INTERCOM_ID) { + userId = config.userId + const data = { app_id: INTERCOM_ID, - user_id: config.userId, + user_id: userId, created_at: config.createdAt, name: config.name, - email: config.email, 'App Version': version }