npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

intercom-service-js

v1.2.2

Published

Library for interacting with Intercom built the native intercom-client package

Downloads

112

Readme

Intercom Service for Node JS

Communicate with the Intercom API from your Node JS backend. This package is built on top of the offical intercom-node package. It gives you TypeScript type definitions for all exported functions and will validate the incoming data so it complies with the rules of the Intercom API.

Quickstart

  yarn add intercom-service-js

Basic Usage

Basic usage involves adding the IntercomService to your setup. IMPORTANT You need to fetch your own access token and feed it to IntercomService (as seen below). Read more here Create an Access Token.

import { IntercomService } from 'intercom-service-js'

// Initialize the IntercomService
const intercom = new IntercomService({ token: process.env.INTERCOM_AUTH_TOKEN })
// ways down in your code ...
intercom.createOrUpdateUser({
    user_id: `${data.user_id}`,
    name: data.user_name,
    email: data.user_email,
    signed_up_at: data.user_created_date,
    companies: [
      {
        company_id: `${data.company_id}`,
      },
    ],
    custom_attributes: {
      timezone: data.user_timezone,
      city: data.user_city,
    },
  })
  .then(intercomUpdate => {
    if (intercomUpdate && intercomUpdate.success) {
      resolve({
        success: true,
      })
    } else {
      resolve({
        success: false,
        error: intercomUpdate.error,
      })
    }
  })
  .catch(error => {
    resolve({
      success: false,
      error: error,
    })
  })

API

All functions will return a Promise with the following structure (? suffix indicates it's optional). Note: this syntax is a TypeScript interface.

{
  success: boolean
  data?: {
    internal_id: string
    intercom_id: string
    result: {
      // This contains the body of the response from the API
      [propName: string]: any
    }
  }
  error?: {
    code: string
    message: string
    errors: string[]
    data?: {
      internal_id: string
    }
    originalError?: any
  }
}

Regarding async/await

Please note we're using await (of async/await) in the examples below. We're using TypeScript to allow that but there are lot's of other ways so pick your favourite.

tagCompany

Example

const tagResult = await intercom.tagCompany({
  company_id: '1234',
  tag: 'test tag',
})

Accepts

  • company_id (string)
  • tag (object)

Mandatory

  • company_id
  • tag

tagMultiple

Example

const tagResult = await intercom.tagCompany({
  name: 'test tag',
  companies: [
    {
      company_id: '1234'
    }
  ],
  users: [
    {
      user_id: '5678'
    }
  ]
})

Accepts

  • An object with the following fields (see type for more information)
    • name (string)
    • companies (Array<object>)
    • users (Array<object>)

Mandatory

  • name
  • companies
  • users

createOrUpdateCompany

Example

const result = await intercom.createOrUpdateCompany({ company_id: '233' })

Accepts

  • company_id (string)
  • remote_created_at (string)
  • name (string)
  • monthly_spend (number)
  • plan (string)
  • size (number)
  • website (string)
  • industry (string)
  • custom_attributes (object)

Mandatory

  • company_id

createOrUpdateUser

Example

const userDataData = {
  user_id: user.id,
  email: user.email,
  name: user.name,
  companies: [
    {
      company_id: company.id,
    },
  ],
}
const result = await intercom.createOrUpdateUser(userDataData)

Accepts

  • user_id (string)
  • email (string)
  • name (string)
  • phone (string)
  • website (string)
  • signed_up_at (string)
  • last_request_at (string)
  • last_seen_ip (string)
  • last_seen_user_agent (string)
  • update_last_request_at (string)
  • unsubscribed_from_emails (boolean)
  • new_session (boolean)
  • companies (Array<object>)
  • custom_attributes (object)

Mandatory

  • user_id
  • email

deleteUser

Example

const result = await intercom.deleteUser({
  user_id: user.id,
})

Accepts

  • userId (string)

Mandatory

  • userId