Skip to content

Repository files navigation

Note:getstream-ruby is the new full-product SDK for Stream, covering Chat, Video, Moderation, and Feeds with long-term support.

stream-chat-ruby is now in maintenance mode. It will continue to receive critical fixes and requested features, so it is safe to keep using. However, we encourage existing users to migrate when convenient and strongly recommend that new projects start with getstream-ruby.

Check out the Migration Guide for side-by-side examples covering common use cases.

Official Ruby SDK for Stream Chat

buildGem Version

Official Ruby API client for Stream Chat, a service for building chat applications.
Explore the docs »

Code Samples · Report Bug · Request Feature

📝 About Stream

You can sign up for a Stream account at our Get Started page.

You can use this library to access chat API endpoints server-side.

For the client-side integrations (web and mobile) have a look at the JavaScript, iOS and Android SDK libraries (docs).

⚙️ Installation

stream-chat-ruby supports Ruby version 3.0 and greater. We test against Ruby versions 3.0, 3.1 and 3.4.

$ gem install stream-chat-ruby

✨ Getting started

require'stream-chat'client=StreamChat::Client.new('STREAM_KEY','STREAM_SECRET')

💡 Note: since v2.21.0 we implemented Sorbet type checker. As of v2.x.x we only use it for static type checks and you won't notice any difference, but from v3.0.0 we will enable runtime checks 🚨 🚨 🚨.

What this means, is that you'll receive an error during runtime if you pass an invalid type to our methods. To prepare for that, just make sure whatever you pass in, matches the method signature (sig { ... }).

Update (2022-May-24): we have relased v3.0.0 with enabled runtime checks.


Additionally, in a future major version, we would like to enforce symbol hash keys during runtime to conform to Ruby best practises. It's a good idea to prepare your application for that.

# Wrong:user={"user"=>{"id"=>"bob-1"}}# Correct:user={user: {id: "bob-1"}}

Generate a token for client-side usage:

client.create_token('bob-1')

Create/Update users

client.upsert_user({id: 'bob-1',role: 'admin',name: 'Robert Tables'})# Batch update is also supportedjane={id: 'jane-1'}june={id: 'june-1'}client.upsert_users([jane,june])

Channel types

client.create_channel_type({name: 'livechat',automod: 'disabled',commands: ['ban'],mutes: true})channel_types=client.list_channel_types()

Channels

# Create a channel with members from the startchan=client.channel("messaging",channel_id: "bob-and-jane",data: {:members=>['bob-1','jane-77']})chan.create('bob-1')# Create a channel and then add memberschan=client.channel("messaging",channel_id: "bob-and-jane")chan.create('bob-1')chan.add_members(['bob-1','jane-77'])

Reactions

chan.send_reaction(m1['id'],{type: 'like'},'bob-1')

Moderation

chan.add_moderators(['jane-77'])chan.demote_moderators(['bob-1'])chan.ban_user('bob-1',timeout: 30)chan.unban_user('bob-1')

Messages

m1=chan.send_message({text: 'Hi Jane!'},'bob-1')deleted_message=client.delete_message(m1['message']['id'])

Reminders

# Create a reminder for a messagereminder=client.create_reminder(m1['message']['id'],'bob-1',DateTime.now + 1)# Create a reminder without a notification time (just mark for later)reminder=client.create_reminder(m1['message']['id'],'bob-1')# Update a reminderupdated_reminder=client.update_reminder(m1['message']['id'],'bob-1',DateTime.now + 2)# Delete a reminderclient.delete_reminder(m1['message']['id'],'bob-1')# Query reminders for a userreminders=client.query_reminders('bob-1')# Query reminders with filtersfilter={'channel_cid'=>'messaging:bob-and-jane'}reminders=client.query_reminders('bob-1',filter)

Devices

jane_phone=client.add_device({:id=>'iOS Device Token',:push_provider=>push_provider.apn,:user_id=>'jane-77'})client.get_devices('jane-77')client.remove_device(jane_phone['id'],jane_phone['user_id'])

Blocklists

client.create_blocklist('my_blocker',%w[fudgecreamsugar])# Enable it on 'messaging' channel typeclient.update_channel_type('messaging',blocklist: 'my_blocker',blocklist_behavior: 'block')client.get_blocklist('my_blocker')client.delete_blocklist('my_blocker')

Export Channels

# Register an exportresponse=client.export_channels({type: 'messaging',id: 'jane'})# Check completionstatus_response=client.get_export_channel_status(response['task_id'])# status_response['status'] == 'pending', 'completed'

Rate limits

# Get all rate limitslimits=client.get_rate_limits# Get rate limits for specific platform(s)limits=client.get_rate_limits(server_side: true)# Get rate limits for specific platforms and endpointslimits=client.get_rate_limits(android: true,ios: true,endpoints: ['QueryChannels','SendMessage'])

✍️ Contributing

We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our Contributor License Agreement (CLA) first. See our license file for more details.

Head over to CONTRIBUTING.md for some development tips.

🧑‍💻 We are hiring!

We've recently closed a $38 million Series B funding round and we keep actively growing. Our APIs are used by more than a billion end-users, and you'll have a chance to make a huge impact on the product within a team of the strongest engineers all over the world.

Check out our current openings and apply via Stream's website.

About

Official Stream Chat API client for Ruby (maintenance mode). For new projects, see getstream-ruby.

Topics

Resources

Contributing

Security policy

Stars

32 stars

Watchers

26 watching

Forks

Releases

Packages

Used by

Contributors

Languages