@@ -22,7 +22,7 @@ This version of the gem is compatible with `Ruby 2.1` and above.
2222
2323Using bundler:
2424
25- gem 'intercom', '~> 3.5.25 '
25+ gem 'intercom', '~> 3.6.2 '
2626
2727## Basic Usage
2828
@@ -132,8 +132,10 @@ intercom.companies.save(company)
132132# Iterate over all companies
133133intercom.companies.all.each {|company | puts %Q( #{ company.name } - #{ company.custom_attributes[" referral_source" ] } ) }
134134intercom.companies.all.map {|company | company.name }
135- # Get a list of users in a company
136- intercom.companies.users(company.id)
135+ # Get a list of users in a company by Intercom Company ID
136+ intercom.companies.users_by_intercom_company_id(company.id)
137+ # Get a list of users in a company by external company_id
138+ intercom.companies.users_by_company_id(company.company_id)
137139# Get a large list of companies using scroll
138140intercom.companies.scroll.each { |comp | puts comp.name}
139141# Please see users scroll for more details of how to use scroll
@@ -149,7 +151,7 @@ intercom.tags.untag(name: 'blue', users: [{user_id: "42ea2f1b93891f6a99000427"}
149151intercom.tags.all.each {|tag | " #{ tag.id } - #{ tag.name } " }
150152intercom.tags.all.map {|tag | tag.name }
151153# Tag companies
152- tag = intercom.tags.tag(name: ' blue' , companies: [{id : " 42ea2f1b93891f6a99000427" }])
154+ tag = intercom.tags.tag(name: ' blue' , companies: [{company_id : " 42ea2f1b93891f6a99000427" }])
153155```
154156
155157#### Segments
@@ -174,6 +176,9 @@ intercom.notes.find_all(user_id: '123').each {|note| puts note.body}
174176
175177#### Conversations
176178``` ruby
179+ # Iterate over all conversations for your app
180+ intercom.conversations.all.each { |convo | ... }
181+
177182# FINDING CONVERSATIONS FOR AN ADMIN
178183# Iterate over all conversations (open and closed) assigned to an admin
179184intercom.conversations.find_all(type: ' admin' , id: ' 7' ).each {|convo | ... }
@@ -191,6 +196,11 @@ intercom.conversations.find_all(email: '
[email protected] ', type: 'user').each {|c
191196intercom.conversations.find_all(
email: ' [email protected] ' ,
type: ' user' ,
unread: false ).each {|
convo | ... }
192197# Iterate over all unread conversations with a user based on the users email
193198intercom.conversations.find_all(
email: ' [email protected] ' ,
type: ' user' ,
unread: true ).each {|
convo | ... }
199+ # Iterate over all conversations for a user with their Intercom user ID
200+ intercom.conversations.find_all(intercom_user_id: ' 536e564f316c83104c000020' , type: ' user' ).each {|convo | ... }
201+ # Iterate over all conversations for a lead
202+ # NOTE: to iterate over a lead's conversations you MUST use their Intercom User ID and type User
203+ intercom.conversations.find_all(intercom_user_id: lead.id, type: ' user' ).each {|convo | ... }
194204
195205# FINDING A SINGLE CONVERSATION
196206conversation = intercom.conversations.find(id: ' 1' )
@@ -218,8 +228,13 @@ intercom.conversations.open(id: conversation.id, admin_id: '123')
218228intercom.conversations.close(id: conversation.id, admin_id: ' 123' )
219229
220230# Assign
231+ # Note: Conversations can be assigned to teams. However, the entity that performs the operation of assigning the conversation has to be an existing teammate.
232+ # You can use `intercom.admins.all.each {|a| puts a.inspect if a.type == 'admin' }` to list all of your teammates.
221233intercom.conversations.assign(id: conversation.id, admin_id: ' 123' , assignee_id: ' 124' )
222234
235+ # Snooze
236+ intercom.conversations.snooze(id: conversation.id, admin_id: ' 123' , snoozed_until: 9999999999 )
237+
223238# Reply and Open
224239intercom.conversations.reply(id: conversation.id, type: ' admin' , admin_id: ' 123' , message_type: ' open' , body: ' bar' )
225240
@@ -357,20 +372,50 @@ The metadata key values in the example are treated as follows-
357372### Contacts
358373
359374` Contacts ` represent logged out users of your application.
375+ Note that ` contacts ` are referred to as ` leads ` in the [ Intercom] ( https://developers.intercom.com/intercom-api-reference/reference#leads )
360376
361377``` ruby
362378# Create a contact
363379contact
= intercom.contacts.create(
email: " [email protected] " )
364380
365- # Update a contact
381+ # Update a contact (via create method)
382+ # You can update a contact by calling the create method but you MUST provide an id or user_id
383+ # If you just provide an email, for example, it will create a new contact
384+ # See https://developers.intercom.com/intercom-api-reference/reference#update-lead for more detail
385+ contact
= intercom.contacts.create(
email: " [email protected] " ,
id: " 3be0398668071a6bc6850413" ,
name: " update_contact" )
386+
387+ # Update a contact (via contact object)
366388contact.custom_attributes[' foo' ] = ' bar'
367389intercom.contacts.save(contact)
368390
369391# Find contacts by email
370392contacts
= intercom.contacts.find_all(
email: " [email protected] " )
371393
394+ # Using find to search for contacts by email
395+ contact_list
= intercom.contacts.find(
email: " [email protected] " )
396+ # This returns a Contact object with type contact.list
397+ # Note: Multiple contacts can be returned in this list if there are multiple matching contacts found
398+ # #<Intercom::Contact:0x00007ff3a80789f8
399+ # @changed_fields=#<Set: {}>,
400+ # @contacts=
401+ # [{"type"=>"contact",
402+ # "id"=>"5b7fd9b683681ac52274b9c7",
403+ # "user_id"=>"05bc4d17-72cc-433e-88ae-0bf88db5d0e6",
404+ # "anonymous"=>true,
405+ 406+ # ...}],
407+ # @custom_attributes={},
408+ # @limited=false,
409+ # @pages=#<Intercom::Pages:0x00007ff3a7413c58 @changed_fields=#<Set: {}>, @next=nil, @page=1, @per_page=50, @total_pages=1, @type="pages">,
410+ # @total_count=1,
411+ # @type="contact.list">
412+ # Access the contact's data
413+ contact_list.contacts.first
414+
372415# Convert a contact into a user
373- intercom.contacts.convert(contact, user)
416+ contact = intercom.contacts.find(id: " 536e564f316c83104c000020" )
417+ intercom.contacts.convert(contact, Intercom ::User .new (email: email))
418+ # Using find with email will not work here. See https://github.com/intercom/intercom-ruby/issues/419 for more information
374419
375420# Delete a contact
376421intercom.contacts.delete(contact)
@@ -441,7 +486,7 @@ intercom.rate_limit_details
441486```
442487
443488You can handle the rate limits yourself but a simple option is to use the handle_rate_limit flag.
444- This will automatically catch the 429 rate limit exceeded error and wait until the reset time to retry.
489+ This will automatically catch the 429 rate limit exceeded error and wait until the reset time to retry. After three retries a rate limit exception will be raised. Encountering this error frequently may require a revisiting of your usage of the API.
445490
446491```
447492intercom = Intercom::Client.new(token: ENV['AT'], handle_rate_limit: true)
0 commit comments