### Install Stream CLI via Homebrew Source: https://github.com/getstream/stream-chat-go/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-go/blob/master/docs/debugging_and_cli/cli_introduction.md Provides an example of a Stream CLI command to get a specific chat channel. ```bash $ stream-cli chat get-channel -t messaging -i redteam ``` -------------------------------- ### Install Stream CLI via Script (Linux x86) Source: https://github.com/getstream/stream-chat-go/blob/master/docs/debugging_and_cli/cli_introduction.md Installs the Stream CLI by downloading the latest release binary for Linux x86 architecture 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 NGROK Source: https://github.com/getstream/stream-chat-go/blob/master/docs/webhooks/webhooks_overview/webhooks_overview.md Install NGROK using Homebrew to facilitate local webhook debugging by exposing your local server to the internet. ```bash brew install ngrok ngrok http 8000 ``` -------------------------------- ### Install stream-chat-go SDK Source: https://github.com/getstream/stream-chat-go/blob/master/README.md Use this command to add the stream-chat-go SDK to your project. ```shell go get github.com/GetStream/stream-chat-go/v8 ``` -------------------------------- ### Install Stream CLI via Script (Windows x86) Source: https://github.com/getstream/stream-chat-go/blob/master/docs/debugging_and_cli/cli_introduction.md Installs the Stream CLI for Windows x86 by downloading the latest release and extracting the archive using PowerShell. ```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-go/blob/master/docs/debugging_and_cli/cli_introduction.md Installs the Stream CLI for Windows ARM by downloading the latest release and extracting the archive using PowerShell. ```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" ``` -------------------------------- ### Install Stream CLI via Script (Linux ARM) Source: https://github.com/getstream/stream-chat-go/blob/master/docs/debugging_and_cli/cli_introduction.md Installs the Stream CLI by downloading the latest release binary for Linux ARM architecture 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 (MacOS Intel) Source: https://github.com/getstream/stream-chat-go/blob/master/docs/debugging_and_cli/cli_introduction.md Installs the Stream CLI by downloading the latest release binary for MacOS Intel architecture using curl and tar. Requires manual quarantine removal. ```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 Stream CLI via Script (MacOS ARM) Source: https://github.com/getstream/stream-chat-go/blob/master/docs/debugging_and_cli/cli_introduction.md Installs the Stream CLI by downloading the latest release binary for MacOS ARM architecture using curl and tar. Requires manual quarantine removal. ```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 ``` -------------------------------- ### Start a Thread Reply in Go Source: https://github.com/getstream/stream-chat-go/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. Ensure you have the `parentMessage.ID` and `userID` available. ```go reply := &Message{Text: "This is a reply in a thread", ParentID: parentMessage.ID} channel.SendMessage(ctx, reply, userID) ``` -------------------------------- ### Create and Update Channel Types in Go Source: https://github.com/getstream/stream-chat-go/blob/master/docs/app_and_channel_settings/channel_types.md Use these examples to create a new channel type with specific configurations or to update an existing one by modifying its properties. ```go // Create a new channel type newChannelType := &ChannelType{ ChannelConfig: DefaultChannelConfig, } newChannelType.Name = "my-channel-type" newChannelType.TypingEvents = true newChannelType.ReadEvents = true newChannelType.Reactions = true newChannelType.Replies = true client.CreateChannelType(newChannelType) // Update an existing channel type client.UpdateChannelType("my-channel-type", map[string]interface{}{ "reactions": false, "max_message_length": 1000, }) ``` -------------------------------- ### Example ChannelState Response JSON Source: https://github.com/getstream/stream-chat-go/blob/master/docs/channels/query_channels.md This is an example of the JSON response structure for a ChannelState object, which contains all necessary information to render a channel without further API calls. ```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" } ] ``` -------------------------------- ### Example SQS Message Format Source: https://github.com/getstream/stream-chat-go/blob/master/docs/webhooks/sqs.md This is an example of the JSON structure for a 'message.new' event received from an SQS queue. It includes details about the message, user, and channel. ```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" } ``` -------------------------------- ### Create User Object Source: https://github.com/getstream/stream-chat-go/blob/master/docs/migrating/import.md Example of a user object with various fields including custom data and roles. Ensure custom fields do not exceed 5 KiB. ```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"}} ``` -------------------------------- ### Channel Template Example Source: https://github.com/getstream/stream-chat-go/blob/master/docs/features/campaign_api.md Defines channel type, ID, and optional team for campaign-driven channel creation. Custom data can be added during channel creation. ```json { "type": "messaging", // channel type is required "id": "{{receiver.id}}-{{sender.id}}", "team": "kansas-city-chiefs", // optional, if provided (and multi tenancy is enabled), you can limit accessibility to the channel only to a team "custom": { // optionally add custom data to channels (only when creating) } } ``` -------------------------------- ### Send Typing Start Event Source: https://github.com/getstream/stream-chat-go/blob/master/docs/features/typing_indicators.md Call the `keystroke` method when a user begins typing. Optionally specify a thread ID for thread-specific indicators. ```go chatClient.Keystroke(ctx, "channel_id", "user_id") ``` -------------------------------- ### Query Channels with Pagination - Go Source: https://github.com/getstream/stream-chat-go/blob/master/docs/channels/query_channels.md Example of querying channels using `QueryChannels` with pagination options like `Limit` and `Offset`. Ensure `members: { $in: [userID] }` is included in the filter for consistent pagination. ```go resp, err := c.QueryChannels(ctx, &QueryOption{ Filter: map[string]interface{}{ "members": map[string]interface{}{ "$in": []string{ "thierry" }, }, }, Sort: []*SortOption{{Field: "last_message_at", Direction: -1}}, Limit: 20, Offset: 10, }) ``` -------------------------------- ### Stream Chat Go Object Format Example Source: https://github.com/getstream/stream-chat-go/blob/master/docs/migrating/import.md This example demonstrates the valid JSON object format for different entity types in Stream Chat Go, including user, device, channel, member, message, and reaction. ```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"}} ``` -------------------------------- ### Query with Dynamic Filter Values Source: https://github.com/getstream/stream-chat-go/blob/master/docs/channels/query_channels.md Provide actual values for predefined filter placeholders at query time. This example shows how to set channel type and users. ```json { "predefined_filter": "user_messaging_channels", "filter_values": { "channel_type": "messaging", "users": ["user123", "user456"] } } ``` -------------------------------- ### Start Live Location Sharing Source: https://github.com/getstream/stream-chat-go/blob/master/docs/features/location_sharing.md Initiate live location sharing by sending a SharedLocation message with an expiration time. Your application must provide periodic location updates. ```go channel := chatClient.CreateChannelWithMembers(ctx, "messaging", channelID, userID) // Create a SharedLocation Object with end_at end_at := time.Now().Add(1 * time.Hour) location := &SharedLocation{ Longitude: &longitude, Latitude: &latitude, EndAt: &end_at, CreatedByDeviceID: "test-device", } // Send a message with the SharedLocation object message := channel.SendMessage(ctx, &Message{ SharedLocation: location, }) ``` -------------------------------- ### Poll Allow User Suggested Options Query Example Source: https://github.com/getstream/stream-chat-go/blob/master/docs/features/polls_api.md Use the '$eq' operator to query for polls based on whether user-suggested options are allowed. ```json { allow_user_suggested_options: { $eq: false } } ``` -------------------------------- ### Autocomplete Members by User Name in Go Source: https://github.com/getstream/stream-chat-go/blob/master/docs/channels/query_members.md This example demonstrates how to perform an autocomplete search for members based on a partial username. It uses the `$autocomplete` operator for efficient searching. ```go // Autocomplete members by user name ch.QueryMembers(ctx, &QueryOption{ Filter: map[string]interface{}{ "name": map[string]interface{}{"$autocomplete": "tom"}, }, }) ``` -------------------------------- ### Send a Message with Attachments and Mentions in Go Source: https://github.com/getstream/stream-chat-go/blob/master/docs/messages/send_message.md Send a message that includes attachments (like images) and mentions specific users. This example also demonstrates custom `ExtraData` and the `MessageSkipPush` option. ```go message := &stream_chat.Message{ Text: "@Josh Check out this image!", Attachments: []*stream_chat.Attachment{ { Type: "image", ThumbURL: "https://bit.ly/2K74TaG", AssetURL: "https://bit.ly/2Uumxti", ExtraData: map[string]interface{}{ "myCustomField": 123, }, }, }, MentionedUsers: []*stream_chat.User{ {ID: "josh-id"}, }, ExtraData: map[string]interface{}{ "priority": "high", }, } filledMessage, err := channel.SendMessage(message, userID, MessageSkipPush) ``` -------------------------------- ### Avoid Broad or Complex Channel Filters Source: https://github.com/getstream/stream-chat-go/blob/master/docs/channels/query_channels.md These examples demonstrate overly broad or complex filters that can lead to performance issues. Avoid type-only filters and deep nesting of logical operators. ```go // ❌ BAD: Type-only filter (too broad) broadFilter := map[string]interface{}{ "type": "messaging", } // ❌ BAD: Deep nesting of logical operators nestedFilter := map[string]interface{}{ "$and": []map[string]interface{}{ { "$or": []map[string]interface{}{ {"frozen": true}, {"disabled": true}, }, }, { "$or": []map[string]interface{}{ {"hidden": true}, {"muted": true}, }, }, }, } ``` -------------------------------- ### Create and Use a Custom Blocklist Source: https://github.com/getstream/stream-chat-go/blob/master/docs/best_practices/moderation.md This example demonstrates how to create a new blocklist with custom words and then configure a channel type to use this blocklist for blocking messages. The `blocklist_behavior` can be set to `block` or `flag`. ```go // add a new blocklist for this app blocklistReq := &BlocklistCreateRequest{BlocklistBase{Name: "no-cakes", Words: []string{"fudge", "cream", "sugar"}}} client.CreateBlocklist(ctx, blocklistReq) // use the blocklist for all channels of type messaging client.UpdateChannelType(ctx, "messaging", map[string]interface{}{ "blocklist": "no-cakes", "blocklist_behavior": "block", }) ``` -------------------------------- ### Poll Updated Event Example Source: https://github.com/getstream/stream-chat-go/blob/master/docs/features/polls_api.md An example of the `poll.updated` websocket event payload. ```APIDOC ## Poll Updated Event Example ```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" } ``` ``` -------------------------------- ### Common Filters Example Source: https://github.com/getstream/stream-chat-go/blob/master/docs/channels/query_channels.md Example of a common filter pattern for messaging and team channels, focusing on channel type and membership. ```APIDOC ## Common Filters - Messaging and Team Channels ### Description This section provides an example of a common and performant filter pattern for querying messaging and team channels, emphasizing filtering by channel type and user membership. ### Filter Example ```json { "type": "messaging", "members": { "$in": [ "thierry" ] } } ``` ### Performance Considerations - Filters using indexed fields like `cid`, `type`, `members`, and `last_message_at` perform best. - For users with a large number of channel memberships, consider adding additional filters (e.g., `last_message_at`) to improve query performance when using `members: { $in: [userID] }`. ``` -------------------------------- ### Initialize Stream Chat Client in Go Source: https://github.com/getstream/stream-chat-go/blob/master/README.md Demonstrates different ways to initialize the Stream Chat client, including using API keys and secrets, with a custom timeout, or solely from environment variables. Ensure error handling for client initialization. ```go package main import ( os "os" stream "github.com/GetStream/stream-chat-go/v8" ) var APIKey = os.Getenv("STREAM_KEY") var APISecret = os.Getenv("STREAM_SECRET") var userID = "" // your server user id func main() { // Initialize client client, err := stream.NewClient(APIKey, APISecret) // Or with a specific timeout client, err := stream.NewClient(APIKey, APISecret, WithTimeout(3 * time.Second)) // Or using only environmental variables: (required) STREAM_KEY, (required) STREAM_SECRET, // (optional) STREAM_CHAT_TIMEOUT client, err := stream.NewClientFromEnvVars() // handle error // Define a context ctx := context.Background() // use client methods // create channel with users users := []string{"id1", "id2", "id3"} userID := "id1" channel, err := client.CreateChannelWithMembers(ctx, "messaging", "channel-id", userID, users...) // use channel methods msg, err := channel.SendMessage(ctx, &stream.Message{Text: "hello"}, userID) } ``` -------------------------------- ### Campaign Started Webhook Event Source: https://github.com/getstream/stream-chat-go/blob/master/docs/features/campaign_api.md Receives an event when a campaign starts. Includes the full campaign object with its status and stats. ```json { "type": "campaign.started", "campaign": { "status": "running", "stats": {...}, ... }, "created_at": "2024-23-02 00:00:00" } ``` -------------------------------- ### Unread Reminder Event Example Source: https://github.com/getstream/stream-chat-go/blob/master/docs/messages/unread_reminders.md An example of the event payload received when a user has unread messages for a configured reminder interval. This event contains user and channel information. ```json { "type": "user.unread_message_reminder", "created_at": "2022-09-22T12:11:01.258013863Z", "user": { "id": "jose", "role": "user", "created_at": "2021-08-20T08:16:15.591073Z", "updated_at": "2022-09-22T12:07:39.675943Z", "last_active": "2022-09-21T09:49:09.750498Z", "banned": false, "online": false, "teams": ["blue"], "name": "jose" }, "channels": { "messaging:!members-NsJg6rJv7n1wrpi4NyA5zNGBCpih_eYaQdY6KARmEHo": { "channel": { "id": "!members-NsJg6rJv7n1wrpi4NyA5zNGBCpih_eYaQdY6KARmEHo", "type": "messaging", "cid": "messaging:!members-NsJg6rJv7n1wrpi4NyA5zNGBCpih_eYaQdY6KARmEHo", "last_message_at": "2022-09-22T12:10:01.833367Z", "created_at": "2022-08-24T17:19:28.792836Z", "updated_at": "2022-08-24T17:19:28.792836Z", "frozen": false, "disabled": false, "member_count": 2, "members": [ { "user_id": "jose", "user": { "id": "jose", "name": "jose" }, "role": "member" }, { "user_id": "pepe", "user": { "id": "pepe" }, "role": "owner" } ] }, "messages": [ { "id": "8009180a-ef37-4818-b4fd-e69a7312d77e", "text": "hola", "type": "regular", "user": { "id": "pepe" }, "created_at": "2022-09-22T12:05:05.641171Z" } ] } } } ``` -------------------------------- ### Compile Stream CLI from Source Source: https://github.com/getstream/stream-chat-go/blob/master/docs/debugging_and_cli/cli_introduction.md Compiles the Stream CLI from source by cloning the repository, navigating into the directory, and running the go build command. Includes checking the version. ```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 Help Commands Source: https://github.com/getstream/stream-chat-go/blob/master/docs/debugging_and_cli/cli_introduction.md Demonstrates how to access help information for the Stream CLI at different levels of command specificity. ```bash $ stream-cli --help $ stream-cli chat --help $ stream-cli chat get-channel --help ``` -------------------------------- ### Create a new custom command Source: https://github.com/getstream/stream-chat-go/blob/master/docs/webhooks/webhooks_overview/custom_commands_webhook.md Define and create a new custom command using the Command struct. Specify the name, description, arguments help text, and set name for grouping. ```go newCommand := &Command{ Name: "ticket", Description: "Create a support ticket", Args: "[description]", Set: "support_commands_set", } client.CreateCommand(ctx, newCommand) ``` -------------------------------- ### Get a Channel Type Source: https://github.com/getstream/stream-chat-go/blob/master/docs/app_and_channel_settings/channel_types.md Retrieves a specific channel type definition. ```APIDOC ## GET /api/channel-types/{channel_type_name} ### Description Retrieves a specific channel type definition. ### Method GET ### Endpoint /api/channel-types/{channel_type_name} ### Parameters #### Path Parameters - **channel_type_name** (string) - Required - The name of the channel type to retrieve. ### Response #### Success Response (200) - **channel_type** (object) - The channel type object. #### Response Example ```json { "channel_type": { "name": "public", "mutes": false, "reactions": false } } ``` ``` -------------------------------- ### Instantiate Stream Client and Create User Token Source: https://github.com/getstream/stream-chat-go/blob/master/docs/quick_start/backend_quickstart.md Instantiate the Stream client with your API key and secret. Use this to create a user token on the server, which is then handed to the client for authentication. The secret is only used server-side. ```go // go get github.com/GetStream/stream-chat-go import stream "github.com/GetStream/stream-chat-go/v5" import "time" // instantiate your stream client using the API key and secret // the secret is only used server side and gives you full access to the API client, err := stream.NewClient("{{ api_key }}", "{{ api_secret }}") token, err := client.CreateToken("john", time.Time{}) // next, hand this token to the client in your in your login or registration response ``` -------------------------------- ### Create a New Blocklist Source: https://github.com/getstream/stream-chat-go/blob/master/docs/best_practices/moderation.md Creates a new blocklist for the application with a specified name and a list of words to block. ```go blocklistReq := &BlocklistCreateRequest{BlocklistBase{Name: "no-cakes", Words: []string{"fudge", "cream", "sugar"}}} client.CreateBlocklist(ctx, blocklistReq) ``` -------------------------------- ### Poll ID Query Example Source: https://github.com/getstream/stream-chat-go/blob/master/docs/features/polls_api.md Use the '$in' operator to query for polls with specific IDs. ```json { id: { $in: [ 'abcd', 'defg' ] } } ``` -------------------------------- ### Get a specific custom command Source: https://github.com/getstream/stream-chat-go/blob/master/docs/webhooks/webhooks_overview/custom_commands_webhook.md Retrieve the definition of a specific custom command by its name. ```go client.GetCommand(ctx, "ticket") ``` -------------------------------- ### Create a Server Client and Generate a Token Source: https://github.com/getstream/stream-chat-go/blob/master/docs/init_and_users/tokens_and_authentication.md Use this to generate a client-side token by passing the user ID. Ensure the user ID is included in the token payload for client-side usage. ```go // github.com/GetStream/stream-chat-go/v3 serverClient, _ := stream.NewClient(APIKey, APISecret) token := serverClient.CreateToken("john", expiredAt, issuedAt) ``` -------------------------------- ### Poll Name Query Example Source: https://github.com/getstream/stream-chat-go/blob/master/docs/features/polls_api.md Use the '$eq' operator to query for polls with a specific name. ```json { name: { $eq: 'abcd' } } ``` -------------------------------- ### Poll Is Closed Query Example Source: https://github.com/getstream/stream-chat-go/blob/master/docs/features/polls_api.md Use the '$eq' operator to query for polls based on their closed status. ```json { is_closed: { $eq: true } } ``` -------------------------------- ### Watch Existing Channel with Server Side Auth Source: https://github.com/getstream/stream-chat-go/blob/master/docs/debugging_and_cli/api_errors_response.md This code snippet demonstrates watching an existing channel. If the channel does not exist and server-side authentication is used, it may lead to a 'GetOrCreateChannel failed' error if not created beforehand. ```go channel, err := chatClient.Channel("messaging", "123").Watch(ctx, nil) if err != nil { log.Fatalf("%v", err) } ``` -------------------------------- ### Get Campaign Stats Source: https://github.com/getstream/stream-chat-go/blob/master/docs/features/campaign_api.md Fetch statistics for a completed campaign. This provides insights into the campaign's performance. ```go stats, err := chatClient.GetCampaignStats("campaign-id") ``` -------------------------------- ### Stream CLI Basic Syntax Source: https://github.com/getstream/stream-chat-go/blob/master/docs/debugging_and_cli/cli_introduction.md Illustrates the basic command syntax for the Stream CLI, specifying 'chat' or 'feeds' as the primary module. ```bash $ stream-cli [chat|feeds] [command] [args] [options] ``` -------------------------------- ### Paginate Channel Members by Created At (Ascending) Source: https://github.com/getstream/stream-chat-go/blob/master/docs/channels/query_members.md Use this method to paginate channel members by `created_at` in ascending order. This is a recommended approach for reliable pagination. ```go ch.QueryMembers(ctx, &QueryOption{ Filter: make(map[string]interface{}), Offset: 0, Limit: 10, }, &SortOption{Field: "created_at", Direction: -1}, ) ``` -------------------------------- ### Poll Queryable Fields Source: https://github.com/getstream/stream-chat-go/blob/master/docs/features/polls_api.md This section lists the fields that can be queried for polls, along with their types, supported operations, and examples. ```APIDOC ## Poll Queryable Fields This section lists the fields that can be queried for polls, along with their types, supported operations, and examples. ### Fields - **id** (string or list of strings) - The ID of the vote. Supported operations: $in, $eq. Example: `{ id: { $in: [ 'abcd', 'defg' ] } }` - **poll_id** (string or list of strings) - The ID of the poll. Supported operations: $in, $eq. Example: `{ poll_id: { $in: [ 'abcd', 'defg' ] } }` - **name** (string or list of strings) - The ID of the user who casted the vote. Supported operations: $in, $eq. Example: `{ name: { $eq: 'abcd' } }` - **voting_visibility** (string) - Indicates whether the votes are casted anonymously. Supported operations: $eq. Example: `{ voting_visibility: { $eq: 'anonymous' } }` - **max_votes_allowed** (number) - The maximum amount of votes per user. Supported operations: $eq, $ne, $gt, $lt, $gte, $lte. Example: `{ max_votes_allowed: { $gte: 5 } }` - **allow_user_suggested_options** (boolean) - Indicates whether the poll allows user suggested options. Supported operations: $eq. Example: `{ allow_user_suggested_options: { $eq: false } }` - **allow_answers** (boolean) - Indicates whether the poll allows user answers. Supported operations: $eq. Example: `{ allow_answers: { $eq: false } }` - **is_closed** (boolean) - Indicates whether the poll is closed for voting. Supported operations: $eq. Example: `{ is_closed: { $eq: true } }` - **created_at** (string, must be formatted as an RFC3339 timestamp) - The time the poll was created. Supported operations: $eq, $gt, $lt, $gte, $lte. Example: `{ created_at: {$gte: ‘2023-12-04T09:30:20.45Z’ }` - **updated_at** (string, must be formatted as an RFC3339 timestamp) - The time the poll was updated. Supported operations: $eq, $gt, $lt, $gte, $lte. Example: `{ updated_at: {$gte: ‘2023-12-04T09:30:20.45Z’ }` - **created_by_id** (string or list of strings) - The ID of the user who created the poll. Supported operations: $in, $eq. Example: `{ id: { $in: [ 'abcd', 'defg' ] } }` ``` -------------------------------- ### Poll Voting Visibility Query Example Source: https://github.com/getstream/stream-chat-go/blob/master/docs/features/polls_api.md Use the '$eq' operator to query for polls with a specific voting visibility. ```json { voting_visibility: { $eq: 'anonymous' } } ``` -------------------------------- ### Poll Allow Answers Query Example Source: https://github.com/getstream/stream-chat-go/blob/master/docs/features/polls_api.md Use the '$eq' operator to query for polls based on whether user answers are allowed. ```json { allow_answers: { $eq: false } } ``` -------------------------------- ### Use Predefined Filters for Production Queries Source: https://github.com/getstream/stream-chat-go/blob/master/docs/channels/query_channels.md For frequently used query patterns in production, utilize predefined filters with 'PredefinedFilter' and 'FilterValues'. Ensure 'userID' is defined. ```go // Production-ready: Use Predefined Filter resp, err := c.QueryChannels(ctx, &QueryOption{ PredefinedFilter: "user_messaging_channels", FilterValues: map[string]interface{}{ "user_id": userID, }, Sort: []*SortOption{{Field: "last_message_at", Direction: -1}}, Limit: 20, }) ``` -------------------------------- ### Decompress GZIP Payload Source: https://github.com/getstream/stream-chat-go/blob/master/docs/webhooks/webhooks_overview/webhooks_overview.md Use `GunzipPayload` to decompress a byte slice if it starts with the GZIP magic bytes. Otherwise, the body is returned unchanged. ```go inflatedBody, err := stream.GunzipPayload(body) if err != nil { // handle decompression error } ``` -------------------------------- ### Query Reminders with Pagination Options Source: https://github.com/getstream/stream-chat-go/blob/master/docs/messages/message_reminders.md Fetch reminders for a user with specified limits and offsets for pagination. This is useful for handling large numbers of reminders. ```go // Load reminders with pagination options := map[string]interface{}{ "limit": 10, "offset": 0, } reminders, err := client.QueryReminders(ctx, "user-id", nil, options) ``` -------------------------------- ### Add Push Webhook Source: https://github.com/getstream/stream-chat-go/blob/master/docs/webhooks/webhooks_overview/webhooks_overview.md This snippet shows how to add a new push webhook while preserving existing configurations. It first retrieves current settings, then adds the new webhook, and finally updates the application settings. ```go // 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 settings, err := client.GetAppSettings(ctx) if err != nil { log.Fatal(err) } existingHooks := settings.App.EventHooks fmt.Printf("Current event hooks: %+v\n", existingHooks) // STEP 2: Add webhook hook while preserving existing hooks newWebhookHook := EventHook{ HookType: WebhookHook, Enabled: true, EventTypes: []string{}, // empty slice = all events WebhookURL: "https://example.com/webhooks/stream/push", } // STEP 3: Update with complete array including existing hooks allHooks := append(existingHooks, newWebhookHook) _, err = client.UpdateAppSettings(ctx, NewAppSettings().SetEventHooks(allHooks)) if err != nil { log.Fatal(err) } // Test the webhook connection req := &CheckPushRequest{ WebhookURL: "https://example.com/webhooks/stream/push", } client.CheckPush(ctx, req) ``` -------------------------------- ### Get a Channel Segment Source: https://github.com/getstream/stream-chat-go/blob/master/docs/features/campaign_api.md Retrieve a specific segment by its ID. The response contains detailed information about the segment, including its size and creation date. ```go segment, err := chatClient.GetSegment("all-my-channels") ``` -------------------------------- ### Poll Updated At Query Example Source: https://github.com/getstream/stream-chat-go/blob/master/docs/features/polls_api.md Use comparison operators like '$gte' with RFC3339 formatted timestamps to query for polls updated after a specific time. ```json { updated_at: {$gte: ‘2023-12-04T09:30:20.45Z’ } ``` -------------------------------- ### Stream CLI Autocompletion Help Source: https://github.com/getstream/stream-chat-go/blob/master/docs/debugging_and_cli/cli_introduction.md Shows how to access help for the autocompletion feature of the Stream CLI. ```bash $ stream-cli completion --help ``` -------------------------------- ### Example JSON Response for Inline Reply Source: https://github.com/getstream/stream-chat-go/blob/master/docs/messages/threads.md When querying messages, the `quoted_message` field is automatically populated if an inline reply was used. This shows the structure of the response. ```json { "id": "new-message-id", "text": "I agree with this point", "quoted_message_id": "original-message-id", "quoted_message": { "id": "original-message-id", "text": "The original message text" } } ``` -------------------------------- ### Configure Before Message Send and Custom Commands Webhooks Source: https://github.com/getstream/stream-chat-go/blob/master/docs/webhooks/webhooks_overview/webhooks_overview.md Configure the URLs for the 'Before Message Send' and 'Custom Commands' webhooks using the AppSettings. These webhooks use a distinct configuration method and are not part of the multi-event hooks system. ```go settings := &AppSettings{ BeforeMessageSendHookURL: "https://example.com/webhooks/stream/before-message-send", // sets Before Message Send webhook address CustomActionHandlerURL: "https://example.com/webhooks/stream/custom-commands?type={type}", // sets Custom Commands webhook address } client.UpdateAppSettings(ctx, settings) ```