Code Monkey home page Code Monkey logo

intercom.io's Introduction

intercom.io

http://tarunc.github.io/intercom.io/

An API client in Node.JS for talking to intercom.io. This package implements the complete API (no longer; some of the API) for talking with the intercom.io API -- users, messages, impressions, tags, notes and more. This library's methods support promises (methodName().then(resolve, reject))(thru q) and node style callbacks (methodName(function(err, data){ /* callback code */ })).

There complete docs can be found here - http://doc.intercom.io/api. See docs for complete API documentation of this library and all the methods that we support. See tests for more examples.

NOTE: This library is not maintained be me anymore. Pull requests are still welcome and will be merged appropriately. I recommend using Intercom's Node Library instead.

Installation

To install the latest stable release with the command-line tool:

npm install --save intercom.io

Usage

See this library's docs for complete API documentation and the intercom API documentation.

var Intercom = require('intercom.io');

var options = {
  personalAccessToken: "your_access_token", // Intercom Access Token
  timeout: 60 * 1000 // Timeout (in ms) for requests to the intercom API
};

var intercom = new Intercom(options);
// Can also be written as:
// var intercom = new Intercom("your_access_token");


// Usage with appId and apiKey
// appId and appKey will be disabled on intercom as of Jan 2017 and will be replaced by Personal Access Tokens
// See https://developers.intercom.com/docs/personal-access-tokens
var options = {
  apiKey: "your_API_key", // Your Personal Intercom API Key
  appId: "your_APP_ID" // Your Intercom App Id
};

var intercom = new Intercom(options);
// Can also be written as:
// var intercom = new Intercom("your_APP_ID", "your_API_key");

// Note: you can also require and create an instance in the same step if you would like.
// Example:
// var intercom = require('intercom.io').create("your_APP_ID", "your_API_key");
// or
// var intercom = require('intercom.io').create(options);

// To create a user
// Every method supports promises or callbacks.
intercom.createUser({
  "email" : "[email protected]",
  "user_id" : "7902",
  "name" : "Ben McRedmond",
  "created_at" : 1257553080,
  "custom_data" : {"plan" : "pro"},
  "last_seen_ip" : "1.2.3.4",
  "last_seen_user_agent" : "ie6",
  "companies" : [
    {
      "id" : 6,
      "name" : "Intercom",
      "created_at" : 103201,
      "plan" : "Messaging",
      "monthly_spend" : 50
    }
  ],
  "last_request_at" : 1300000000
}, function(err, res) {
  // err is an error object if there was an error
  // res is **JSON** response
  // In this case:
  // {
  //   "intercom_id": "52322b3b5d2dd84f23000169",
  //   "email": "[email protected]",
  //   "user_id": "7902",
  //   "name": "Ben McRedmond",
  //   "created_at": 1257553080,
  //   "last_impression_at": 1300000000,
  //   "custom_data": {
  //     "plan": "pro"
  //   },
  // ...
  // ...
  // ...
  //   "session_count": 0,
  //   "last_seen_ip": "1.2.3.4",
  //   "last_seen_user_agent": "ie6",
  //   "unsubscribed_from_emails": false
  // }
});

// To get a user
// (using a promise)
intercom.getUser({ "email": "[email protected]" }).then(function(res) {
  // res is **JSON** response
  // In this case:
  // {
  //   "intercom_id": "52322b396823b17b1100016a",
  //   "email": "[email protected]",
  //   "user_id": "7902",
  //   "name": "Ben McRedmond",
  //   "created_at": 1257553080,
  //   "last_impression_at": 1300000000,
  //   "custom_data": {
  //     "plan": "pro"
  //   },
  // ...
  // ...
  // ...
  //   "session_count": 0,
  //   "last_seen_ip": "1.2.3.4",
  //   "last_seen_user_agent": "ie6",
  //   "unsubscribed_from_emails": false
  // }
}, function(err) {
  // err is an error object if there was an error
});

// To get multiple users
intercom.getUsers({
  page: 1,
  per_page: 500,
  tag_id: 7002,
  tag_name: "me"
}, function (err, res) {
  // err is an error object
  // res is the **JSON** response
  // {
  //   "users": [
  //     {
  //       "intercom_id": "52322b366823b173eb000170",
  //       "email": "[email protected]",
  //       "user_id": "123",
  //       "name": "First User",
  //       "created_at": 1270000000,
  //       "last_impression_at": 1300000000,
  //       "custom_data": {
  //         "app_name": "Genesis",
  // ...
  // ...
  // ...
  //       "last_seen_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
  //       "unsubscribed_from_emails": false
  //     }
  //   ],
  //   "total_count": 3,
  //   "page": 1,
  //   "next_page": null,
  //   "previous_page": null,
  //   "total_pages": 1
  // }
});

List of supported methods: (More methods on docs.)

* intercom.getPages
* intercom.getUsers
* intercom.getUser
* intercom.viewUser
* intercom.createUser
* intercom.updateUser
* intercom.deleteUser
* intercom.bulkAddUsers
* intercom.createContact
* intercom.updateContact
* intercom.deleteContact
* intercom.getContact
* intercom.viewContact
* intercom.getContacts
* intercom.convertContact
* intercom.listCompanies
* intercom.viewCompany
* intercom.createCompany
* intercom.updateCompany
* intercom.listCompanyUsers
* intercom.listAdmins
* intercom.createNote
* intercom.listNotes
* intercom.viewNote
* intercom.getTag
* intercom.createTag
* intercom.deleteTag
* intercom.updateTag
* intercom.listSegments
* intercom.viewSegment
* intercom.createEvent
* intercom.getCounts
* intercom.createUserMessage
* intercom.listConversations
* intercom.getConversation
* intercom.replyConversation
* intercom.markConversationAsRead
* intercom.closeConversation

See docs for complete API documentation and the intercom API documentation. See tests for more examples.

Note: Every method returns a promise but accepts callbacks too.

License

(The MIT License)

Copyright (c) 2013-2018 Tarun Chaudhry <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

intercom.io's People

Contributors

aetheon avatar asciimike avatar askhogan avatar criroselli avatar csakbalint avatar erisds avatar flamparski avatar holm avatar homeyer avatar jamesramsay avatar kessiler avatar mderazon avatar monkbroc avatar nolanamy avatar notbrain avatar pakerhoi avatar ryedog avatar stefanosala avatar strml avatar tarunc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

intercom.io's Issues

406 Error when calling createUser

  var options = {
    apiKey: "HIDDEN",
    appId: "HIDDEN"
  };

  var intercom = new Intercom(options);
  intercom.createUser({
    "email": "[email protected]",
    "name": "Tom Gallagher"
  }, function(err, res) {
    console.log(err);
    console.log(res);
  });

Results in:

XMLHttpRequest cannot load https://api.intercom.io/users. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 406.
main.js:175758 null

Any ideas?
Many thanks, Tom.

Date handling

I can safely use Date objects for standard user attributes:

intercom.createUser({
  ...,
  last_request_at: session.used
}, cb);

But for custom data I have to convert to an integer timestamp in seconds:

customData['Last used app'] = Math.round(session.used.getTime()/1000);

Using a Date in custom data gives a very old time in Intercom (perhaps Unix time 0), and using an integer timestamp in milliseconds gives a time far in the future.

Perhaps intercom.io should check for Date objects in custom data and automatically convert them to Intercom-friendly timestamps.

Company update

Hi there, thanks for your module.

However, impossible to update a company as you use a 'PUT' when the official intercom documentation specify a 'POST' for both creation and update.

Just so you know.

++

Methods for retrieving all pages of a resource?

I'm writing custom scripts now to retrieve all the pages of a resource, but can make it pretty and submit a PR to have a pagedRequest method or similar. Let me know if you'd like to have this included :)

Unpublished NPM version

Quick heads up, it looks like v1.2.0 was unpublished from NPM.

This caused our production app to crash when it attempted (and failed) run npm install.

updateUser should use "POST" instead of "PUT"

Hi -- I just ran into 404 errors when calling updateUser, but when I manually change the method from PUT to POST, it works fine.

For now, I'm using the createUser call instead, since it seems identical in every other way.

missing data validity check for createUser() and updateUSer()

I was sending an object as updateUser() like so:
https://gist.github.com/fabriziomoscon/dc54598c5be16f28621e

and I was always getting server errors every now and then

from Intercom.io engeneer:

...
Based on the documentation of this library and my knowledge of our API, I can see a couple issues that could be causing the errors:

  1. You need to send all custom data inside a hash; looks like everything below the email attribute in your gist needs to be nested in a custom_data hash.
  2. We do not support arrays or hashes for custom data, so attributes like 'promocodes', 'promocodes_unsued', and 'operating_area' will cause errors.

Also the documentation has a reference on how to pass and validate custom_attributes
We should add some check to the function. So to help future users not to waste time like I did =)

Security Issue with qs dependency

Version 0.6.6 of the qs package has a security vulnerability according to nsp. Could you please update that dependency to a later version. Thanks!

Release 1.5.1

Hi! Would you be able to cut a release 1.5.1 with the bugfix for #43

increments

Hi,

I'm wondering how to do increments?

I see increments mentioned here.

Should I just use updateUser and increments propeprty?

Intercom errors should reject the promise

The current (1.0.0) Intercom.prototype.request implementation parses the json response for errors and sets the err var, but never uses this afterwards. The error should be returned as an rejected promise like a request error would. Additionally, we don't need to check for !err as we would have rejected the promise before if we have gotten an request error.

if (parsed && (parsed.error || parsed.errors) && !err) {
  err = new Error(data);
}
if (parsed && (parsed.error || parsed.errors)) {
  err = new Error(data);
  // Reject the promise
  return deferred.reject(err);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.