### Install and Start NGROK Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/webhooks/webhooks_overview/webhooks_overview.md Use NGROK to expose your local server to the internet for debugging webhook requests. Install NGROK via brew and start an HTTP tunnel. ```bash brew install ngrok ngrok http 8000 ``` -------------------------------- ### Install Stream CLI via Homebrew Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/debugging_and_cli/cli_introduction.md Installs the Stream CLI using Homebrew by tapping the repository and then installing the package. ```bash $ brew tap GetStream/stream-cli https://github.com/GetStream/stream-cli $ brew install stream-cli ``` -------------------------------- ### Stream CLI Example Command Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/debugging_and_cli/cli_introduction.md Provides a concrete example of using the Stream CLI to get a specific chat channel. ```bash $ stream-cli chat get-channel -t messaging -i redteam ``` -------------------------------- ### Example Import File - Ruby Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/migrating/import.md This example demonstrates the structure of a valid import file, showcasing various object types and their data formats. ```json {"type":"user","data":{"id":"user_001","name":"Jesse","image":"http://getstream.com","created_at":"2017-01-01T01:00:00Z","role":"moderator","invisible":true,"description":"Taj Mahal guitar player at some point"}} ``` ```json {"type":"device","data":{"id":"device_001","user_id":"user_001","push_provider_type":"firebase","push_provider_name":"firebase"}} ``` ```json {"type":"channel","data":{"id":"channel_001","type":"messaging","created_by":"user_001","name":"Rock'n Roll Circus"}} ``` ```json {"type":"member","data":{"channel_type":"messaging","channel_id":"channel_001","user_id":"user_001","is_moderator":true,"created_at":"2017-02-01T02:00:00Z"}} ``` ```json {"type":"message","data":{"id":"message_001","channel_type":"messaging","channel_id":"channel_001","user":"user_001","text":"Learn how to build a chat app with Stream","type":"regular","created_at":"2017-02-01T02:00:00Z","attachments":[{"type":"video","asset_url":"https://www.youtube.com/watch?v=o-am4BY-dhs","image_url":"https://i.ytimg.com/vi/o-am4BY-dhs/mqdefault.jpg","thumb_url":"https://i.ytimg.com/vi/o-am4BY-dhs/mqdefault.jpg"}]}} ``` ```json {"type":"reaction","data":{"message_id":"message_001","type":"love","user_id":"user_001","created_at":"2019-03-02T15:00:00Z"}} ``` -------------------------------- ### Install Stream CLI via Script (Linux x86) Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/debugging_and_cli/cli_introduction.md Installs the Stream CLI by downloading the latest release binary for Linux x86 systems using curl and tar. ```bash # Linux x86 $ export URL=$(curl -s https://api.github.com/repos/GetStream/stream-cli/releases/latest | grep Linux_x86 | cut -d '"' -f 4 | sed '1d') $ curl -L $URL -o stream-cli.tar.gz $ tar -xvf stream-cli.tar.gz ``` -------------------------------- ### Install Stream CLI via Script (Linux ARM) Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/debugging_and_cli/cli_introduction.md Installs the Stream CLI by downloading the latest release binary for Linux ARM systems using curl and tar. ```bash # Linux ARM $ export URL=$(curl -s https://api.github.com/repos/GetStream/stream-cli/releases/latest | grep Linux_arm64 | cut -d '"' -f 4 | sed '1d') $ curl -L $URL -o stream-cli.tar.gz $ tar -xvf stream-cli.tar.gz ``` -------------------------------- ### Install Stream CLI via Script (Windows x86) Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/debugging_and_cli/cli_introduction.md Installs the Stream CLI for Windows x86 systems using PowerShell to download and extract the latest release. ```powershell # Windows x86 > $latestRelease = Invoke-WebRequest "https://api.github.com/repos/GetStream/stream-cli/releases/latest" > $json = $latestRelease.Content | ConvertFrom-Json > $url = $json.assets | ? { $_.name -match "Windows_x86" } | select -expand browser_download_url > Invoke-WebRequest -Uri $url -OutFile "stream-cli.zip" > Expand-Archive -Path ".\stream-cli.zip" ``` -------------------------------- ### Install Stream CLI via Script (Windows ARM) Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/debugging_and_cli/cli_introduction.md Installs the Stream CLI for Windows ARM systems using PowerShell to download and extract the latest release. ```powershell # Windows ARM > $latestRelease = Invoke-WebRequest "https://api.github.com/repos/GetStream/stream-cli/releases/latest" > $json = $latestRelease.Content | ConvertFrom-Json > $url = $json.assets | ? { $_.name -match "Windows_arm" } | select -expand browser_download_url > Invoke-WebRequest -Uri $url -OutFile "stream-cli.zip" > Expand-Archive -Path ".\stream-cli.zip" ``` -------------------------------- ### Example ChannelState Response Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/channels/query_channels.md This is an example of the JSON response when querying channels. It includes detailed information about each channel, its messages, members, and configuration. ```json [ { "id": "f8IOxxbt", "type": "messaging", "cid": "messaging:f8IOxxbt", "last_message_at": "2020-01-10T07:26:46.791232Z", "created_at": "2020-01-10T07:25:37.63256Z", "updated_at": "2020-01-10T07:25:37.632561Z", "created_by": { "id": "8ce4c6e11118ca103a0a7c633dcf60dd", "role": "admin", "created_at": "2019-08-27T17:33:14.442265Z", "updated_at": "2020-01-10T07:25:36.402819Z", "last_active": "2020-01-10T07:25:36.395796Z", "banned": false, "online": false, "image": "https://ui-avatars.com/api/?name=mezie&size=192&background=000000&color=6E7FFE&length=1", "name": "mezie", "username": "mezie" }, "frozen": false, "config": { "created_at": "2020-01-20T10:23:44.878185331Z", "updated_at": "2020-01-20T10:23:44.878185458Z", "name": "messaging", "typing_events": true, "read_events": true, "connect_events": true, "search": true, "reactions": true, "replies": true, "mutes": true, "uploads": true, "url_enrichment": true, "max_message_length": 5000, "automod": "disabled", "automod_behavior": "flag", "commands": [ { "name": "giphy", "description": "Post a random gif to the channel", "args": "[text]", "set": "fun_set" } ] }, "name": "Video Call" } ] ``` -------------------------------- ### Install Stream CLI via Script (MacOS Intel) Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/debugging_and_cli/cli_introduction.md Installs the Stream CLI by downloading the latest release binary for MacOS Intel systems using curl and tar. ```bash # MacOS Intel $ export URL=$(curl -s https://api.github.com/repos/GetStream/stream-cli/releases/latest | grep Darwin_x86 | cut -d '"' -f 4 | sed '1d') $ curl -L $URL -o stream-cli.tar.gz $ tar -xvf stream-cli.tar.gz # We don't sign our binaries today, so we need to explicitly trust it. $ xattr -d com.apple.quarantine stream-cli ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/getstream/stream-chat-ruby/blob/master/CONTRIBUTING.md Installs all necessary Ruby gems for the project using Bundler. It's recommended to use the `--path` option to keep gems local to the project. ```shell $ bundle install --path vendor/bundle ``` -------------------------------- ### Install Stream CLI via Script (MacOS ARM) Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/debugging_and_cli/cli_introduction.md Installs the Stream CLI by downloading the latest release binary for MacOS ARM systems using curl and tar. ```bash # MacOS ARM $ export URL=$(curl -s https://api.github.com/repos/GetStream/stream-cli/releases/latest | grep Darwin_arm | cut -d '"' -f 4 | sed '1d') $ curl -L $URL -o stream-cli.tar.gz $ tar -xvf stream-cli.tar.gz # We don't sign our binaries today, so we need to explicitly trust it. $ xattr -d com.apple.quarantine stream-cli ``` -------------------------------- ### Example Query Response Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/features/advanced/audit_logs.md This is an example of the response received when querying message history with specific filters applied. It shows the state of the message at different update times. ```json [ { "message_id": "message-1", "text": "Hello bob! give me a call.", "is_deleted": false, "message_updated_by_id": "alice", "message_updated_at" "2024-04-24T15:47:46" }, { "message_id": "message-1", "text": "Hello bob! give me a call. Here is my number: +31 6 12345678", "is_deleted": false, "message_updated_by_id": "admin", "message_updated_at" "2024-04-24T15:50:21" } ] ``` -------------------------------- ### Create User Object Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/migrating/import.md Example JSON payload for creating a user with basic information, role, and team assignments. ```json {"type":"user","data":{"id":"user_001","name":"Jesse","image":"http://getstream.com","created_at":"2017-01-01T01:00:00Z","role":"moderator","invisible":true,"teams":["admins"],"teams_role":{"admins":"team_moderator"},"description":"Taj Mahal guitar player at some point"}} ``` -------------------------------- ### Install stream-chat-ruby Gem Source: https://github.com/getstream/stream-chat-ruby/blob/master/README.md Install the stream-chat-ruby gem using the RubyGems package manager. Ensure you are using Ruby version 3.0 or greater. ```bash $ gem install stream-chat-ruby ``` -------------------------------- ### Query Channels Example Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/channels/query_channels.md This example demonstrates how to query a list of channels using the Stream Chat Ruby SDK, filtering by members, sorting by last message time, and limiting the results. ```APIDOC ## Query Channels ### Description Retrieves channels based on filter criteria, sorting options, and pagination settings. ### Method POST (Implicit, as SDK methods typically map to API calls) ### Endpoint `/channels` (Implicit, based on SDK usage) ### Parameters #### Query Parameters - **filters** (object) - Required - Filter criteria for channel fields. See [Queryable Fields](#channel-queryable-built-in-fields) for available options. Default: `{}` - **sort** (object or array of objects) - Optional - Sorting criteria based on field and direction. You can sort by **last_updated**, **last_message_at**, **updated_at**, **created_at**, **member_count**, **unread_count**, or **has_unread**. Direction can be ascending (1) or descending (-1). Multiple sort options can be provided. Default: `[{last_updated: -1}]` - **options** (object) - Optional - Additional query options. See [Query Options](#query-options). ### Request Example ```ruby client.query_channels({ 'members' => { '$in' => ['elon', 'jack', 'jessie'] } }, sort: { 'last_message_at' => 1 }, limit: 10 ) ``` ### Response #### Success Response (200) - **channels** (array) - A list of channel objects matching the query criteria. #### Response Example (Response structure not explicitly defined in source, but would contain channel objects) ``` -------------------------------- ### Create and Use a Blocklist for a Channel Type Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/best_practices/moderation.md This example demonstrates how to create a new blocklist with specific words and then configure a channel type to use this blocklist for blocking messages. Ensure the blocklist name and behavior are correctly set. ```ruby # require 'stream-chat' # add a new blocklist for this app client.create_blocklist("no-cakes", words: ["fudge", "cream", "sugar"]) # use the blocklist for all channels of type messaging client.update_channel_type("messaging", blocklist: "no-cakes", blocklist_behavior: "block") ``` -------------------------------- ### Enable Push Notifications with Default Template Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/push/push_template.md This example shows how to enable push notifications for the 'message.new' event using the default APN template. ```APIDOC ## POST /push/templates ### Description Enables push notifications for a specific event type and optionally configures custom templates. ### Method POST ### Endpoint /push/templates ### Request Body - **enable_push** (Boolean) - Required - Indicates whether push notifications are enabled for this event type. - **event_type** (String) - Required - The type of event used to apply the corresponding custom push configuration. Supported values include `message.new`, `message.updated`, `reaction.new`. - **push_provider_type** (String) - Required - The type of push provider (e.g., `apn`, `firebase`). - **push_provider_name** (String) - Optional - The name of the configured push provider instance. Can be left empty if you're not using multi-bundle support. ### Request Example ```json { "enable_push": true, "event_type": "message.new", "push_provider_type": "apn", "push_provider_name": "apn" } ``` ### Response #### Success Response (200) - **message** (String) - Confirmation message. #### Response Example ```json { "message": "Push template updated successfully." } ``` ``` -------------------------------- ### Channel Template Example Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/features/campaign_api.md Define channel properties using Jinja-style variables for dynamic channel IDs. The channel type is required, and optional fields like 'team' can be included for multi-tenancy. ```json { "type": "messaging", "id": "{{receiver.id}}-{{sender.id}}", "team": "kansas-city-chiefs", "custom": { } } ``` -------------------------------- ### Add, Get, and Remove Devices Source: https://github.com/getstream/stream-chat-ruby/blob/master/README.md Manage user devices by adding new device tokens, retrieving a list of devices for a user, and removing a specific device. Requires a valid push provider configuration. ```ruby 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']) ``` -------------------------------- ### Create and Manage Channels Source: https://github.com/getstream/stream-chat-ruby/blob/master/README.md Create channels, optionally specifying members from the start or adding them later. The `channel` method prepares a channel object, and `create` finalizes its creation. ```ruby # Create a channel with members from the start chan = client.channel("messaging", channel_id: "bob-and-jane", data: {:members => ['bob-1', 'jane-77']}) chan.create('bob-1') ``` ```ruby # Create a channel and then add members chan = client.channel("messaging", channel_id: "bob-and-jane") chan.create('bob-1') chan.add_members(['bob-1', 'jane-77']) ``` -------------------------------- ### Query Reminders Source: https://github.com/getstream/stream-chat-ruby/blob/master/README.md Allows querying reminders with specific filters. The example shows how to query reminders for a given user within a specific channel. ```APIDOC ## Query Reminders ### Description Query reminders with filters. ### Method `client.query_reminders(user_id, filter)` ### Parameters #### Path Parameters - **user_id** (string) - Required - The ID of the user whose reminders are to be queried. - **filter** (object) - Required - A hash containing filter criteria for the reminders. ### Request Example ```ruby filter = { 'channel_cid' => 'messaging:bob-and-jane' } reminders = client.query_reminders('bob-1', filter) ``` ``` -------------------------------- ### Stream CLI Autocompletion Help Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/debugging_and_cli/cli_introduction.md Shows how to get help for the autocompletion feature of the Stream CLI, which supports shells like PowerShell, Bash, ZSH, and Fish. ```bash $ stream-cli completion --help ``` -------------------------------- ### Enable Push Notifications with Custom Template Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/push/push_template.md This example demonstrates enabling push notifications for 'message.new' event with a custom Firebase template. ```APIDOC ## POST /push/templates ### Description Enables push notifications for a specific event type and optionally configures custom templates. ### Method POST ### Endpoint /push/templates ### Request Body - **enable_push** (Boolean) - Required - Indicates whether push notifications are enabled for this event type. - **event_type** (String) - Required - The type of event used to apply the corresponding custom push configuration. Supported values include `message.new`, `message.updated`, `reaction.new`. - **push_provider_type** (String) - Required - The type of push provider (e.g., `apn`, `firebase`). - **push_provider_name** (String) - Optional - The name of the configured push provider instance. Can be left empty if you're not using multi-bundle support. - **template** (String) - Optional - The push notification template as a stringified JSON object. ### Request Example ```json { "enable_push": true, "event_type": "message.new", "push_provider_type": "firebase", "push_provider_name": "firebase", "template": "{\"data\":{\"version\":\"v2\",\"sender\":\"stream.chat\",\"type\":\"{{ event_type }}\",\"id\":\"{{ message.id }}\",\"message_id\":\"{{ message.id }}\",\"channel_type\":\"{{ channel.type }}\",\"channel_id\":\"{{ channel.id }}\",\"cid\":\"{{ channel.cid }}\",\"receiver_id\":\"{{ receiver.id }}\"},\"android\":{\"priority\":\"high\"},\"apns\":{\"payload\":{\"aps\":{\"alert\":{\"title\":\"New message from {{ sender.name }}\",\"body\":\"{{ truncate message.text 150 }}\"},\"badge\":{{ unread_count }},\"sound\":\"default\",\"mutable-content\":1,\"content-available\":0}}}}" } ``` ### Response #### Success Response (200) - **message** (String) - Confirmation message. #### Response Example ```json { "message": "Push template updated successfully." } ``` ``` -------------------------------- ### Truncate a Channel Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/channels/channel_management/truncating.md Demonstrates how to truncate a channel using the `truncate` method on a channel object. It shows a basic call and an example with additional parameters. ```APIDOC ## Truncate a Channel This operation removes all messages from a channel while retaining the channel's data and members. It can be performed client-side (requiring `TruncateChannel` permission) or server-side. ### Method Signature ```ruby channel.truncate(options = {}) ``` ### Parameters #### Options - **truncated_at** (Date) - Optional - Truncate messages up to this time. - **user_id** (string) - Optional - User who performed the truncation (server-side only). - **message** (object) - Optional - A system message to add after truncation. It can contain `text` and `user_id`. - **skip_push** (bool) - Optional - If `true`, do not send a push notification for the system message. - **hard_delete** (bool) - Optional - If `true`, permanently delete messages instead of hiding them. ### Request Example ```ruby # Basic truncation channel.truncate # Truncation with a system message and other options text = "Dear Everyone. The channel has been truncated." channel.truncate(skip_push: true, message: { text: text, user_id: @user[:id] }) ``` ### Notes - To permanently delete a channel and its messages, use the [Delete Channel](/chat/docs/ruby/channel_delete/) method. - Server-side truncation requires the `user_id` to identify the performing user. - By default, messages are hidden. Set `hard_delete: true` for permanent deletion. ``` -------------------------------- ### Start Live Location Sharing Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/features/location_sharing.md Initiate live location sharing by sending a message with location data that includes an expiration time. Your application must provide subsequent location updates. ```ruby @location_channel = @client.channel('messaging', channel_id: SecureRandom.uuid) location = { created_by_device_id: SecureRandom.uuid, latitude: 40.7128, longitude: -74.0060, end_at: (Time.now + 3600).iso8601 } response = @location_channel.send_message({ shared_location: location }) ``` -------------------------------- ### Create Symbolic Link for Stream CLI Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/debugging_and_cli/cli_introduction.md Creates a symbolic link to the stream-cli executable, allowing it to be run as 'stream'. This is useful if 'imagemagick' is not installed. ```bash $ ln -s ~/Downloads/stream-cli /usr/local/bin/stream $ stream --version stream-cli version 1.0.0 ``` -------------------------------- ### Create and Update Channel Types Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/app_and_channel_settings/channel_types.md Examples demonstrating how to create a new channel type and update an existing one using the Stream Chat Ruby client. ```APIDOC ## Create Channel Type ### Description Creates a new channel type with specified features and configurations. ### Method `client.create_channel_type(options) ### Parameters #### Request Body - **name** (string) - Required - The name of the channel type. - **typing_events** (boolean) - Optional - Enables typing indicators. - **read_events** (boolean) - Optional - Enables read events. - **reactions** (boolean) - Optional - Enables reactions. - **replies** (boolean) - Optional - Enables replies. ### Request Example ```ruby client.create_channel_type({ 'name' => 'my-channel-type', 'typing_events' => true, 'read_events' => true, 'reactions' => true, 'replies' => true }) ``` ## Update Channel Type ### Description Updates an existing channel type with new configurations. ### Method `client.update_channel_type(channel_type_name, options) ### Parameters #### Path Parameters - **channel_type_name** (string) - Required - The name of the channel type to update. #### Request Body - **reactions** (boolean) - Optional - Updates the reactions setting. - **max_message_length** (integer) - Optional - Sets the maximum message length. ### Request Example ```ruby client.update_channel_type( 'my-channel-type', reactions: false, max_message_length: 1000 ) ``` ``` -------------------------------- ### Example Thread List Response Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/messages/threads.md This JSON structure represents a list of threads a user participates in, including parent message details, reply counts, and latest replies. ```json { "threads": [ { "channel_cid": "messaging:general", "channel": { "id": "general", "type": "messaging", "name": "General" }, "parent_message_id": "parent-123", "parent_message": { "id": "parent-123", "text": "Original message", "type": "regular" }, "created_by_user_id": "user-1", "reply_count": 5, "participant_count": 3, "thread_participants": [ { "user_id": "user-1", "user": { "id": "user-1", "name": "Alice" } }, { "user_id": "user-2", "user": { "id": "user-2", "name": "Bob" } } ], "last_message_at": "2024-12-11T15:30:00Z", "latest_replies": [ { "id": "reply-1", "text": "Latest reply", "type": "reply" } ], "read": [ { "user": { "id": "user-1" }, "last_read": "2024-12-11T15:00:00Z", "unread_messages": 2 } ] } ] } ``` -------------------------------- ### Example Reaction Data Structure Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/messages/send_reaction.md This JSON structure illustrates the fields returned for message reactions, including counts, scores, detailed groups, latest reactions, and the current user's reactions. ```json { "reaction_counts": { "love": 3, "fire": 2, "thumbsup": 1 }, "reaction_scores": { "love": 3, "fire": 2, "thumbsup": 1 }, "reaction_groups": { "love": { "count": 3, "sum_scores": 3, "first_reaction_at": "2024-12-11T14:32:00.000Z", "last_reaction_at": "2024-12-11T15:18:00.000Z" }, "fire": { "count": 2, "sum_scores": 2, "first_reaction_at": "2024-12-11T14:35:00.000Z", "last_reaction_at": "2024-12-11T14:52:00.000Z" }, "thumbsup": { "count": 1, "sum_scores": 1, "first_reaction_at": "2024-12-11T16:05:00.000Z", "last_reaction_at": "2024-12-11T16:05:00.000Z" } }, "latest_reactions": [ { "type": "thumbsup", "user_id": "sarah-miller", "created_at": "2024-12-11T16:05:00.000Z" }, { "type": "love", "user_id": "mike-johnson", "created_at": "2024-12-11T15:18:00.000Z" }, { "type": "fire", "user_id": "emma-wilson", "created_at": "2024-12-11T14:52:00.000Z" } ], "own_reactions": [] } ``` -------------------------------- ### Query Reminders with Pagination Options Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/messages/message_reminders.md Retrieve reminders for a user with specified pagination options, including `limit` for the number of results and `offset` for the starting point. This is essential for handling large numbers of reminders. ```ruby options = { limit: 10, offset: 0 } reminders = client.query_reminders('user-id', {}, options) ``` -------------------------------- ### Campaign Webhook Events Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/features/campaign_api.md Example JSON payloads for campaign start and completion webhook events. These events notify your server when a campaign's status changes. ```json { "type": "campaign.started", "campaign": { "status": "running", "stats": {...}, ... }, "created_at": "2024-23-02 00:00:00" } ``` ```json { "type": "campaign.completed", "campaign": { "status": "completed", "stats": {...}, ... }, "created_at": "2024-23-02 00:00:00" } ``` -------------------------------- ### Example SQS Message Structure Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/webhooks/sqs.md This is an example of the JSON structure for messages that Stream sends to your SQS queue. It includes event details, message content, and user information. ```json { "type": "message.new", "cid": "messaging:fun-d5f396e3-fbaf-469c-9b45-8837b4f75baa", "message": { "id": "8bffc454-e1da-4d91-8b88-a87853dfb41c", "text": "Welcome to the Community!", "html": "
Welcome to the Community!
\n", "type": "regular", "user": { "id": "tommaso-52ec3a5f-e916-469f-bf54-b53b5247a4b0", "role": "user", "created_at": "2020-03-30T07:54:46.207332Z", "updated_at": "2020-03-30T07:54:46.207719Z", "banned": false, "online": false }, "attachments": [], "latest_reactions": [], "own_reactions": [], "reaction_counts": null, "reaction_scores": {}, "reply_count": 0, "created_at": "2020-03-30T07:54:46.277381Z", "updated_at": "2020-03-30T07:54:46.277382Z", "mentioned_users": [] }, "user": { "id": "tommaso-52ec3a5f-e916-469f-bf54-b53b5247a4b0", "role": "user", "created_at": "2020-03-30T07:54:46.207332Z", "updated_at": "2020-03-30T07:54:46.207719Z", "banned": false, "online": false, "channel_unread_count": 0, "channel_last_read_at": "2020-03-30T07:54:46.270208768Z", "total_unread_count": 0, "unread_channels": 0, "unread_count": 0 }, "created_at": "2020-03-30T07:54:46.295138Z", "members": [ { "user_id": "thierry-735d0d44-8bf1-40df-81db-fa83363ac790", "user": { "id": "tommaso-52ec3a5f-e916-469f-bf54-b53b5247a4b0", "role": "user", "created_at": "2020-03-30T07:54:46.207332Z", "updated_at": "2020-03-30T07:54:46.207719Z", "banned": false, "online": false }, "created_at": "2020-03-30T07:54:46.255628Z", "updated_at": "2020-03-30T07:54:46.255628Z" } ], "channel_type": "messaging", "channel_id": "fun-d5f396e3-fbaf-469c-9b45-8837b4f75baa" } ``` -------------------------------- ### Start a Thread Reply in Ruby Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/messages/threads.md Send a message with a `parent_id` to start a new thread or add a reply to an existing one. This keeps main channel conversations clean. ```ruby channel.send_message( { text: "This is a reply in a thread", parent_id: parent_message_id }, user_id, ) ``` -------------------------------- ### Add Push Webhook to Existing Hooks Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/webhooks/webhooks_overview/webhooks_overview.md This example demonstrates how to add a new push webhook while preserving existing configurations. It involves fetching current settings, defining the new webhook, and updating the app settings with the combined list. ```ruby # Note: Any previously existing hooks not included in event_hooks array will be deleted. # Get current settings first to preserve your existing configuration. # STEP 1: Get current app settings to preserve existing hooks response = client.get_app_settings existing_hooks = response["event_hooks"] || [] puts "Current event hooks:", existing_hooks # STEP 2: Add webhook hook while preserving existing hooks new_webhook_hook = { "enabled" => true, "hook_type" => "webhook", "webhook_url" => "https://example.com/webhooks/stream/push", "event_types" => [] # empty array = all events } # STEP 3: Update with complete array including existing hooks client.update_app_settings( event_hooks: existing_hooks + [new_webhook_hook] ) # Test the webhook connection client.check_push('https://example.com/webhooks/stream/push') ``` -------------------------------- ### Stream CLI Help Commands Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/debugging_and_cli/cli_introduction.md Demonstrates how to access help information at different levels of the Stream CLI, from the root command to specific subcommands. ```bash $ stream-cli --help $ stream-cli chat --help $ stream-cli chat get-channel --help ``` -------------------------------- ### Create a Custom Command - Ruby Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/webhooks/webhooks_overview/custom_commands_webhook.md Register a new custom command with its name, description, and arguments help text. ```ruby client.create_command({ name: 'ticket', description: 'Create a support ticket', args: '[description]', set: 'support_commands_set' }) ``` -------------------------------- ### Compile Stream CLI from Source Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/debugging_and_cli/cli_introduction.md Compiles the Stream CLI from its source code by cloning the repository and running the Go build command. ```bash $ git clone git@github.com:GetStream/stream-cli.git $ cd stream-cli $ go build ./cmd/stream-cli $ ./stream-cli --version stream-cli version 1.0.0 ``` -------------------------------- ### Stream CLI Basic Syntax Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/debugging_and_cli/cli_introduction.md Illustrates the general command structure for the Stream CLI, which involves specifying a service (chat or feeds), a command, arguments, and options. ```bash $ stream-cli [chat|feeds] [command] [args] [options] ``` -------------------------------- ### Get a Channel Type Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/app_and_channel_settings/channel_types.md Retrieves a specific channel type definition by its name. ```APIDOC ## Get a Channel Type ### Description Retrieves a channel type definition with this endpoint. Features and commands are also returned by other channel endpoints. ### Method GET (assumed, based on get operation) ### Endpoint /channel_types/{channel_type_name} ### Parameters #### Path Parameters - **channel_type_name** (string) - Required - The name of the channel type to retrieve. ### Request Example ```ruby client.get_channel_type('public') ``` ### Response #### Success Response (200) - **type** (object) - The channel type object. #### Response Example (Example not provided in source) ``` -------------------------------- ### Get a Command Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/webhooks/webhooks_overview/custom_commands_webhook.md API method to retrieve a specific custom command definition by its name. ```APIDOC ## Get a Command ```ruby client.get_command("ticket") ``` ``` -------------------------------- ### Getting a Thread by ID Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/messages/threads.md Retrieve a specific thread using the parent message ID. ```APIDOC ## Getting a Thread by ID ### Description Retrieve a specific thread using the parent message ID. ### Method `client.get_thread(message_id:)` ### Parameters #### Path Parameters - **message_id** (String) - Required - The ID of the parent message for the thread. ### Response #### Success Response (200) - **thread** (Object) - The thread object. ### Response Example ```json { "thread": { "id": "thread-1", "user_id": "user-1", "message": { "id": "message-1", "text": "Hello!" } } } ``` ``` -------------------------------- ### Get a Specific Channel Type Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/app_and_channel_settings/channel_types.md Retrieve the definition of a specific channel type by its name. ```ruby client.get_channel_type('public') ``` -------------------------------- ### Production-Ready Query: Using Predefined Filters Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/channels/query_channels.md Utilize predefined filters for frequently used query patterns in production. This ensures consistency, enables performance monitoring, and allows for optimization insights. Ensure 'user_id' is defined. ```ruby # Production-ready: Use Predefined Filter channels = client.query_channels( predefined_filter: 'user_messaging_channels', filter_values: { 'user_id' => user_id }, sort: { 'last_message_at' => -1 }, limit: 20 ) ``` -------------------------------- ### Get a Specific Custom Command - Ruby Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/webhooks/webhooks_overview/custom_commands_webhook.md Fetch the definition of a single custom command by its name. ```ruby client.get_command("ticket") ``` -------------------------------- ### Get List of Blocked Users (Server-Side) Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/best_practices/moderation.md Server-side implementation to retrieve a list of users that a specific user has blocked. ```ruby @client.get_user_blocks(user_id: user_id) ``` -------------------------------- ### Create a Guest User Session in Frontend Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/init_and_users/authless_users.md Use `setGuestUser` instead of `connectUser` to generate a guest user session in a front-end client. Guest users are counted towards MAU usage and have limited permissions. ```javascript const user = { id: 'guest-1', name: 'Guest User', email: 'guest@example.com' }; await chatClient.setGuestUser(user); ``` -------------------------------- ### Get Campaign Statistics Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/features/campaign_api.md Fetch detailed statistics for a campaign by its ID. This provides insights into the campaign's performance. ```ruby campaign_id = "your-campaign-id" client.getCampaign(campaign_id).stats ``` -------------------------------- ### Pin a Channel Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/channels/channel_management/pinning.md This snippet shows how to get a channel object, pin it for a specific user, and then query for channels that are pinned. ```APIDOC ## Pin a Channel ### Description Allows a channel member to pin a channel for themselves. This is a per-user setting. ### Method ```ruby # Get a channel channel = client.channel("messaging", "general") # Pin the channel for user amy user_id = "amy" response = channel.pin(user_id) ``` ### Query Pinned Channels ### Description Retrieves channels that have been pinned by a specific user. ### Method ```ruby # Query for channels that are pinned user_id = "amy" response = client.query_channels({ 'pinned': true }, sort: nil, user_id: user_id) ``` ### Query and Sort Pinned Channels ### Description Retrieves channels for specific members and sorts them to display pinned channels first. ### Method ```ruby # Query for channels for specific members and show pinned first user_id = "amy" response = client.query_channels( { 'members' => { '$in' => [ 'amy', 'ben' ] } }, sort: { 'pinned_at': -1 }, user_id: user_id ) ``` ### Unpin a Channel ### Description Removes the pinned status of a channel for a specific user. ### Method ```ruby # Unpin the channel user_id = "amy" response = channel.unpin(user_id) ``` ``` -------------------------------- ### Search Messages with Cursor Pagination Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/messages/search.md Demonstrates how to fetch the first page of search results and then navigate to subsequent or previous pages using the `next` and `previous` cursors. Custom sorting is applied. ```ruby channel_filters = { cid: 'messaging:my-channel' } message_filters = { text: { '$autocomplete': 'supercali' }} # First page page1 = client.search( channel_filters, message_filters, sort: [{ relevance: -1 }, { updated_at: 1 }, { my_custom_field: -1 }], limit: 10 ) # Next page page2 = client.search(channel_filters, message_filters, next: page1.next, limit: 10) # Previous page page1_again = client.search(channel_filters, message_filters, next: page2.previous, limit: 10) ``` -------------------------------- ### Poll Updated Event Structure Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/features/polls_api.md Example JSON payload for a 'poll.updated' websocket event. This event is emitted when a poll or its options are modified. ```json { "type": "poll.updated", "cid": "messaging-polls:a23de673-dcc4-413f-9923-4d1af0a6f596", "channel_id": "a23de673-dcc4-413f-9923-4d1af0a6f596", "channel_type": "messaging-polls", "message": { // ... }, "poll": { "id": "3598617e-228b-480a-8004-f441ff195da2", "name": "Updated poll name", "description": "", "voting_visibility": "public", "enforce_unique_vote": false, "max_votes_allowed": null, "allow_user_suggested_options": false, "allow_answers": false, "vote_count": 0, "options": [], "vote_counts_by_option": {}, "answers_count": 0, "latest_votes_by_option": {}, "latest_answers": [], "own_votes": [], "created_by_id": "b3e6cf5b-d431-40f5-8022-27d246b3a890", "created_by": { "id": "b3e6cf5b-d431-40f5-8022-27d246b3a890", "role": "user", "created_at": "2024-04-09T20:43:39.192829Z", "updated_at": "2024-04-09T20:43:39.192829Z", "last_active": "2024-04-09T20:43:39.192829Z", "banned": false, "online": true }, "created_at": "2024-04-09T20:43:39.360335Z", "updated_at": "2024-04-09T20:43:39.940022Z" }, "created_at": "2024-04-09T20:43:39.96665Z", "received_at": "2024-04-09T20:43:39.971Z" } ``` -------------------------------- ### Archive, Query, and Unarchive a Channel Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/channels/channel_management/archiving.md Demonstrates how to archive a channel for a specific user, query for archived channels, and then unarchive the channel. Ensure the user ID is correctly specified for these operations. ```ruby # Get a channel channel = client.channel("messaging", "general") # Archive the channel for user amy user_id = "amy" response = channel.archive(user_id) # Query for channels that are archived response = client.query_channels({ 'archived': true }, sort: nil, user_id: user_id) # Unarchive the channel response = channel.unarchive(user_id) ``` -------------------------------- ### Callback Request Body Example Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/features/advanced/pending_messages.md This JSON structure represents the body of the POST request sent to your callback endpoint for pending messages. ```json { "message": { // the message object }, "metadata": { // keys and values that you passed as pending_message_metadata }, "request_info": { // request info of the request that sent the pending message. Example: /* "type": "client", "ip": "127.0.0.1", "user_agent": "Mozilla/5.0...", "sdk": "stream-chat-js", "ext": "additional-data" */ } } ``` -------------------------------- ### Create a New Blocklist Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/best_practices/moderation.md Creates a new blocklist with a specified name and a list of words to be moderated. Words should be in lowercase and up to 40 characters long. ```ruby client.create_blocklist("no-cakes", words: ["fudge", "cream", "sugar"]) ``` -------------------------------- ### Paginate Members by Creation Date (Ascending) Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/channels/query_members.md Use this to paginate members sorted by creation date in ascending order. Ensure the 'channel' object is initialized. ```ruby response = channel.query_members( filter_conditions: {}, sort: [{ "field" => "created_at", "direction" => -1 }], offset: 0, limit: 10, ) ``` -------------------------------- ### Update User Privacy Settings Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/migrating/import.md Example JSON payload for updating a user's privacy settings, such as delivery receipts and typing indicators. ```json {"type":"user","data":{"id":"user_001","privacy_settings":{"delivery_receipts":{"enabled":true},"typing_indicators":{"enabled":true},"read_receipts":{"enabled":true}}}} ``` -------------------------------- ### Test Push Notification with Custom APN Template Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/push/push_test.md This example demonstrates how to test a specific APN notification template by providing it directly in the `check_push` command. This allows for one-time testing of new template configurations without altering the default settings. ```ruby client.check_push({ message_id: message_id, skip_devices: true, user_id: user[:id], apn_template: "{\"aps\":{\"alert\":{\"title\":\"{{ sender.name }} @ {{ channel.name }}\",\"body\":\"testing out new stuff:{{ message.text }}\"}},\"category\":\"NEW_MESSAGE_2\"}" }) ``` -------------------------------- ### IDE Settings for Linters and Type Checkers Source: https://github.com/getstream/stream-chat-ruby/blob/master/CONTRIBUTING.md Recommended VS Code settings for integrating Rubocop and Sorbet. These settings enable format on save and configure the respective extensions. ```json { "editor.formatOnSave": true, "ruby.useBundler": true, "ruby.lint": { "rubocop": { "useBundler": true, } }, "ruby.format": "rubocop", "ruby.useLanguageServer": true, "sorbet.enabled": true } ``` -------------------------------- ### Update User Push Preferences Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/migrating/import.md Example JSON payload for configuring a user's push notification preferences, including chat level and disabled until. ```json {"type":"user","data":{"id":"user_001","push_preferences":{"chat_level":"mentions","disabled_until":"2042-01-01T00:00:01Z"}}} ``` -------------------------------- ### Import Device Data - JSON Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/migrating/import.md Use this JSON structure to import device data. Ensure all required fields like 'id', 'user_id', 'push_provider_type', and 'push_provider_name' are included. ```json {"type":"device","data":{"id":"device_001","user_id":"user_001","created_at": "2019-01-11T02:00:00Z","push_provider_type":"firebase","push_provider_name":"production-firebase-config"}} ``` -------------------------------- ### Pin and Query Channels Source: https://github.com/getstream/stream-chat-ruby/blob/master/docs/channels/channel_management/pinning.md Use these methods to pin a channel for a specific user, query for pinned channels, or sort channels to show pinned ones first. Unpinning is also demonstrated. ```ruby # Get a channel channel = client.channel("messaging", "general") # Pin the channel for user amy user_id = "amy" response = channel.pin(user_id) # Query for channels that are pinned response = client.query_channels({ 'pinned': true }, sort: nil, user_id: user_id) # Query for channels for specific members and show pinned first response = client.query_channels( { 'members' => { '$in' => [ 'amy', 'ben' ] } }, sort: { 'pinned_at': -1 }, user_id: user_id ) # Unpin the channel response = channel.unpin(user_id) ```