Git Product home page Git Product logo

intercom-php's Introduction

Code Climate

Build Status

Installation

Requires PHP 5.6.

Using Composer:

The recommended way to install intercom-php is through Composer:

First, install Composer:

$ curl -sS https://getcomposer.org/installer | php

Next, install the latest intercom-php:

$ php composer.phar require intercom/intercom-php

Finally, you can include the files in your PHP script:

require "vendor/autoload.php";

Clients

For OAuth or Access Tokens use:

use Intercom\IntercomClient;

$client = new IntercomClient(<insert_token_here>, null);

If you already have an access token you can find it here. If you want to create or learn more about access tokens then you can find more info here.

If you are building a third party application you can get your OAuth token by setting-up-oauth for Intercom.

Users

// Create a user
$client->users->create([
  "email" => "[email protected]",
  "custom_attributes" => ['foo' => 'bar']
]);

// Update a user (Note: This method is an alias to the create method. In practice you can use create to update users if you wish)
$client->users->update([
  "email" => "[email protected]",
  "custom_attributes" => ['foo' => 'bar']
]);

// Delete a user by ID
$client->users->deleteUser("570680a8a1bcbca8a90001b9");

// Get a user by ID
$client->users->getUser("570680a8a1bcbca8a90001b9");

// Add companies to a user
$client->users->create([
  "email" => "[email protected]",
  "companies" => [
    [
      "company_id" => "3"
    ]
  ]
]);

// Remove companies from a user
$client->users->create([
  "email" => "[email protected]",
  "companies" => [
    [
      "company_id" => "3",
      "remove" => true
    ]
  ]
]);

// Find a single user by email
$client->users->getUsers(["email" => "[email protected]"]);

// List all users
$client->users->getUsers([]);

Leads

// Create a lead
// See more options here: https://developers.intercom.io/reference#create-lead
$client->leads->create([
  "email" => "[email protected]",
  "custom_attributes" => ['foo' => 'bar']
]);

// Update a lead (Note: This method is an alias to the create method. In practice you can use create to update leads if you wish)
$client->leads->update([
  "email" => "[email protected]",
  "custom_attributes" => ['foo' => 'bar']
]);

// List leads
// See more options here: https://developers.intercom.io/reference#list-leads
$client->leads->getLeads([]);

// Find a lead by ID
$client->leads->getLead("570680a8a1bcbca8a90000a9");

// Delete a lead by ID
$client->leads->deleteLead("570680a8a1bcbca8a90000a9");

// Convert a Lead to a User
$client->leads->convertLead([
  "contact" => [
    "user_id" => "8a88a590-e1c3-41e2-a502-e0649dbf721c"
  ],
  "user" => [
    "email" => "[email protected]"
  ]
]);

Visitors

Retrieve user_id of a visitor via the Javscript API

// Update a visitor
$client->visitors->update([
  "user_id" => "8a88a590-e1c3-41e2-a502-e0649dbf721c",
  "custom_attributes" => ['foo' => 'bar']
]);

// Find a visitor by ID
$client->visitors->getVisitor("570680a8a1bcbca8a90000a9");

// Find a visitor by User ID
$client->visitors->getVisitor("", ["user_id" => "8a88a590-e1c3-41e2-a502-e0649dbf721c"]);

// Delete a visitor by ID
$client->visitors->deleteVisitor("570680a8a1bcbca8a90000a9");

// Convert a Visitor to a Lead
$client->visitors->convertVisitor([
  "visitor" => [
    "user_id" => "8a88a590-e1c3-41e2-a502-e0649dbf721c"
  ],
  "type" => "lead"
]);

// Convert a Visitor to a User
$client->visitors->convertVisitor([
  "visitor" => [
    "user_id" => "8a88a590-e1c3-41e2-a502-e0649dbf721c"
  ],
  "user" => [
    "email" => "[email protected]"
  ],
  "type" => "user"
]);

Tags

// List tags
$client->tags->getTags();

// Tag users
// See more options here: https://developers.intercom.io/reference#tag-or-untag-users-companies-leads-contacts
$client->tags->tag([
  "name" => "Test",
  "users" => [
    ["id" => "1234"]
  ]
]);

Segments

// List Segments
$client->segments->getSegments();

Events

// Create an event
$client->events->create([
  "event_name" => "testing",
  "created_at" => 1391691571,
  "email" => "[email protected]"
]);

// View events for a user
$client->events->getEvents(["email" => "[email protected]"]);

Companies

// Create a company
$client->companies->create([
  "name" => "foocorp", "company_id" => "3"
]);

// Update a company (Note: This method is an alias to the create method. In practice you can use create to update companies if you wish)
$client->companies->update([
  "name" => "foocorp", "id" => "3"
]);

// Creating or Update a company with custom attributes.
$client->companies->update([
  "name" => "foocorp",
  "id" => "3",
  "custom_attributes" => [
    "foo" => "bar",
    "baz" => "qux"
  ]
]);

// List Companies
$client->companies->getCompanies([]);

Admins

// List admins
$client->admins->getAdmins();

Messages

// Send a message from an admin to a user
// See more options here: https://developers.intercom.io/reference#conversations
$client->messages->create([
  "message_type" => "inapp",
  "subject" => "Hey",
  "body" => "Ponies, cute small horses or something more sinister?",
  "from" => [
    "type" => "admin",
    "id" => "1234"
  ],
  "to" => [
    "type" => "user",
    "email" => "[email protected]"
  ]
]);

Conversations

// List conversations for an admin
// See more options here: https://developers.intercom.io/reference#list-conversations
$client->conversations->getConversations([
  "type" => "admin",
  "admin_id" => "25610"
]);

// Get a single conversation
$client->conversations->getConversation("1234")
// Get a single conversation with plaintext comments
$client->conversations->getConversation("1234", [
  "display_as" => "plaintext"
])


// Reply to a conversation
// See more options here: https://developers.intercom.io/reference#replying-to-a-conversation
$client->conversations->replyToConversation("5678", [
  "email" => "[email protected]",
  "body" => "Thanks :)",
  "type" => "user",
  "message_type" => "comment"
]);

//Reply to a user's last conversation
// See more options here: https://developers.intercom.com/reference#replying-to-users-last-conversation
$client->conversations->replyToLastConversation([
  "email" => "[email protected]",
  "body" => "Thanks :)",
  "type" => "user",
  "message_type" => "comment"
]);

// Mark a conversation as read
// See API documentation here: https://developers.intercom.io/reference#marking-a-conversation-as-read
$client->conversations->markConversationAsRead("7890");

Counts

// List counts
// See more options here: https://developers.intercom.io/reference#getting-counts
$client->counts->getCounts([])

Notes

// Create a note
$client->notes->create([
  "admin_id" => "21",
  "body" => "Text for my note",
  "user" => [
    "id" => "5310d8e8598c9a0b24000005"
  ]
]);

// List notes for a user
$client->notes->getNotes([
  "user_id" => "25"
]);

// Get a single Note by id
$client->notes->getNote("42");

Pagination

When listing, the Intercom API may return a pagination object:

{
  "pages": {
    "next": "..."
  }
}

You can grab the next page of results using the client:

$client->nextPage($response->pages);

Exceptions

Exceptions are handled by Guzzle. The Intercom API may return an unsuccessful HTTP response, for example when a resource is not found (404). If you want to catch errors you can wrap your API call into a try/catch:

use GuzzleHttp\Exception\ClientException;

try {
  $user = $client->users->getUser("570680a8a1bcbca8a90001b9");
} catch(ClientException $e) {
  $response = $e->getResponse();
  $statusCode = $response->getStatusCode();
  if ($statusCode == '404') {
    // Handle 404 error
    return;
  } else {
    throw $e;
  }
}

Pull Requests

  • Add tests! Your patch won't be accepted if it doesn't have tests.

  • Document any change in behaviour. Make sure the README and any other relevant documentation are kept up-to-date.

  • Create topic branches. Don't ask us to pull from your master branch.

  • One pull request per feature. If you want to do more than one thing, send multiple pull requests.

  • Send coherent history. Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before sending them to us.

intercom-php's People

Contributors

dannyfallon avatar nurazem avatar bobjflong avatar josler avatar dehora avatar ruairik avatar mmartinic avatar eugeneius avatar ziemkowski avatar kmossco avatar thewheat avatar klimesf avatar bviolier avatar andrewtseipp avatar fnwbr avatar joe-gaudet-hs avatar falldi avatar choran avatar shibby avatar rb-cohen avatar luoshiben avatar kareypowell avatar robwalkerco avatar plippe avatar 512banque avatar jerrebm avatar isaacesso avatar c4pone avatar donaldwasserman avatar antoinelemaire avatar

Watchers

 avatar

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.