Skip to content

Commit

Permalink
fix(app): Grab intercom handler from window on every call (#2179)
Browse files Browse the repository at this point in the history
Our support module was caching the intercom handler too early (before
the window had a chance to load), resulting in all our intercom calls
nooping. This change removes the caching so window.Intercom is always
called correctly.
  • Loading branch information
mcous authored Sep 4, 2018
1 parent 4c5b258 commit a90aaae
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions app/src/support.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// @flow
// user support module
import noop from 'lodash/noop'

import {version} from './../package.json'
import createLogger from './logger'

Expand All @@ -15,10 +13,17 @@ const log = createLogger(__filename)
// pulled in from environment at build time
const INTERCOM_ID = process.env.OT_APP_INTERCOM_ID

// intercom handler (default noop)
let intercom = noop
// intercom user ID
let userId

// intercom handler (default noop)
const intercom = (...args) => {
if (INTERCOM_ID && global.Intercom) {
log.debug('Sending to Intercom', {args})
global.Intercom(...args)
}
}

export function initializeSupport (): ThunkAction {
return (_, getState) => {
const config = getState().config.support
Expand All @@ -32,9 +37,8 @@ export const supportMiddleware: Middleware = (store) => (next) => (action) => {
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})

intercom('update', {user_id: userId, 'Robot Name': robot})
}

return next(action)
Expand All @@ -44,16 +48,12 @@ function initializeIntercom (config: SupportConfig) {
if (INTERCOM_ID) {
userId = config.userId

const data = {
intercom('boot', {
app_id: INTERCOM_ID,
user_id: userId,
created_at: config.createdAt,
name: config.name,
'App Version': version
}

log.debug('Initializing Intercom', {data})
intercom = global.Intercom || intercom
intercom('boot', data)
})
}
}

0 comments on commit a90aaae

Please sign in to comment.