Skip to content

Commit

Permalink
feat(app): Add robot name to intercom on connect (#2069)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kadee80 authored Aug 16, 2018
1 parent e14ceab commit f5be08d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions app/src/support.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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) => {
Expand All @@ -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
}

Expand Down

0 comments on commit f5be08d

Please sign in to comment.