Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app): Grab intercom handler from window on every call #2179

Merged
merged 1 commit into from
Sep 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an uncaught bug because intercom was always nooping; it should've been 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)
})
}
}