Skip to content

Add a snippet class for generating the Intercom snippet#164

Merged
mckenna merged 1 commit intomasterfrom
p/generate-the-intercom-snippet
Oct 19, 2017
Merged

Add a snippet class for generating the Intercom snippet#164
mckenna merged 1 commit intomasterfrom
p/generate-the-intercom-snippet

Conversation

@mckenna
Copy link
Copy Markdown
Member

@mckenna mckenna commented Oct 16, 2017

This adds a Snippet class to the Node client, which is exposed through the client like so:

const { Snippet } = require('intercom-client');
const settings = {
  verificationSecret: 'abc123',
  app_id: 'xyz789',
  user_id: 1,
  email: 'peter@intercom.io',
  name: 'Peter McKenna',
  company: {
    id: 123,
    name: 'Intercom'
  }
};
const snippet = new Snippet(settings);
res.send(snippet.create());

It returns the full snippet, including the user_hash.

@mckenna mckenna force-pushed the p/generate-the-intercom-snippet branch 3 times, most recently from e4eaa7a to aa21597 Compare October 16, 2017 23:37
@mckenna mckenna force-pushed the p/generate-the-intercom-snippet branch 4 times, most recently from 238ef4b to 6bc6066 Compare October 17, 2017 18:29
Comment thread lib/snippet.js
}
}
});
return intercomSettings.join(', ');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

intercomSettings needs to be an array?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Doesn't have to be. I figured keeping each key / value pair as an element in an array makes it much easier to join them into a string and not have to worry about where you need to add commas.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

JSON.stringify won't work here?

Copy link
Copy Markdown
Member Author

@mckenna mckenna Oct 17, 2017

Choose a reason for hiding this comment

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

No, JSON.stringify will quote literally everything (including the braces for the hash), so you'd get this:

const settings = { 
  app_id: 'abc123', 
  name: 'Peter McKenna', 
  user_id: 1 
};

// Returns '{"app_id":"abc123","name":"Peter McKenna","user_id":1}'
JSON.stringify(settings);

It also quotes the key values, which I guess isn't a big deal.

@mckenna mckenna force-pushed the p/generate-the-intercom-snippet branch 3 times, most recently from 49da5e5 to cce0788 Compare October 18, 2017 18:02
Comment thread lib/snippet.js Outdated
if (!settings.verificationSecret) {
throw new Error('You must provide your verification secret in your Intercom settings');
}
if (!settings.user_id && !settings.email) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we make this snippet work for logged out mode as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep! I'll add that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This supports logged out now.

@mckenna mckenna force-pushed the p/generate-the-intercom-snippet branch from cce0788 to 46eff5b Compare October 18, 2017 21:05
@mckenna mckenna merged commit 0921832 into master Oct 19, 2017
@mckenna mckenna deleted the p/generate-the-intercom-snippet branch October 19, 2017 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants