Overview

LAST EDIT Apr 08 2021

Almost all API requests are specific to a channel (e.g. add a message to channel “livestream:rockets”) and as we saw already, channels are organized in groups called channel types. All applications starts with five default channel types, each have different name and are preconfigured to best fit one use-case.

Channel types can be configured with specific permissions and features.

The five default channel types come with good default permission policies. You can find more information on how to manage permissions in the Channel Types section.

There are four built-in channel types:

  • Livestream: Sensible defaults in case you want to build chat like YouTube or Twitch.
  • Messaging: Configured for apps such as WhatsApp or Facebook Messenger.
  • Team: If you want to build your own version of Slack or something similar, start here.
  • Commerce: Good defaults for building something like your own version of Intercom or Drift.

As you can see in the examples below, you can define your own Channel types and configure them to fit your needs. The Channel type allows you to configure these features:

  • typing_events: Controls if typing indicators are shown.
  • read_events: Controls whether the chat shows how far you’ve read.
  • connect_events: Determines if events are fired for connecting and disconnecting to a chat.
  • search: Controls if messages should be searchable (this is a premium feature).
  • reactions: If users are allowed to add reactions to messages.
  • replies: Enables message threads and replies.
  • mutes: Determines if users are able to mute other users.
  • push_notifications: If messages are allowed to generate push notifications.
  • uploads: Allows image and file uploads within messages.
  • url_enrichment: When enabled, messages containing URLs will be enriched automatically with image and text related to the message.

Channel Types Fields

Copied!
nametypedescriptiondefaultoptional
namestringThe name of the channel type must be unique per application
message_retentionstringA number of days or infiniteinfinite
max_message_lengthintThe max message length5,000
typing_eventsdefaultEnable typing eventsdefault
read_eventsbooleanEnable read eventstrue
connect_eventsbooleanEnable connect eventstrue
searchbooleanEnable message searchtrue
reactionsbooleanEnable message reactionstrue
repliesbooleanEnable replies (threads)true
mutesbooleanEnable mutestrue
uploadsbooleanEnable file and image uploadtrue
url_enrichmentbooleanAutomatically enrich URLstrue
automodstringDisabled, simple or AI are valid options for the Automod (AI based moderation is a premium feature)simple
commandslist of stringThe commands that are available on this channel type[]
push_notificationsbooleanEnable push notificationstrue
You need to use server-side authentication to create, edit, or delete a channel type.

Creating a Channel Type

Copied!
1
2
3
4
5
6
7
import { DenyAll, AnyRole } from 'stream-chat'; 
 
await client.createChannelType({ 
	name: 'public', 
	mutes: false, 
	reactions: false, 
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
client.create_channel_type( 
    { 
        "name": "public", 
        "permissions": [ 
            dict( 
                name="Allow reads for all", 
                priority=999, 
                resources=["ReadChannel", "CreateMessage"], 
                action="Allow", 
            ), 
            dict(name="Deny all", priority=1, resources=["*"], action="Deny"), 
        ], 
        "mutes": False, 
        "reactions": False, 
    } 
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
client.create_channel_type({ 
    'name' => 'public', 
    'permissions' => [ 
	{ 
	    'name' => 'Allow reads for all', 
            'priority' => 999, 
	    'resources' => ['ReadChannel', 'CreateMessage'], 
	    'action' => 'Allow', 
	}, 
	{'name' => 'Deny all', 'priority' => 1, 'resources' => ['*'], 'action' => 'Deny'} 
    ], 
    'mutes' => false, 
    'reactions' => false 
})$channelConf = [    'name' => 'public2',$channelConf = [    'name' => 'public2',    'permissions' => [		[		    'name' => 'Allow reads for all',    	          'priority' => 999,		    'resources' => ['ReadChannel', 'CreateMessage'],		    'action' => 'Allow',		],		[			'name' => 'Deny all', 			'priority' => 1,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$channelConf = [ 
    'name' => 'public2', 
    'permissions' => [ 
		[ 
		    'name' => 'Allow reads for all', 
    	          'priority' => 999, 
		    'resources' => ['ReadChannel', 'CreateMessage'], 
		    'action' => 'Allow', 
		], 
		[ 
			'name' => 'Deny all',  
			'priority' => 1,  
			'resources' => ['*'],  
			'action' => 'Deny' 
		] 
    ], 
    'mutes' => false, 
    'reactions' => false 
]; 
 
$type = $client->createChannelType($channelConf);
1
// at the moment we don't have a Java client for server side usage
1
// at the moment we don't have a Swift client for server side usage
1
2
3
4
5
6
7
8
9
var c = new ChannelTypeInput() 
{ 
    Name = "livechat", 
    Automod = Autmod.Disabled, 
    Commands = new List<string>() { Commands.Ban }, 
    Mutes = true 
}; 
 
await client.CreateChannelType(c);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
newChannelType := &ChannelType{ 
	// Copy the default settings. 
	ChannelConfig: DefaultChannelConfig, 
} 
 
newChannelType.Name = "public" 
newChannelType.Mutes = false 
newChannelType.Reactions = false 
newChannelType.Permissions = append(newChannelType.Permissions, 
	&Permission{ 
		Name:      "Allow reads for all", 
		Priority:  999, 
		Resources: []string{"ReadChannel", "CreateMessage"}, 
		Action:    "Allow", 
	}, 
	&Permission{ 
		Name:      "Deny all", 
		Priority:  1, 
		Resources: []string{"*"}, 
		Action:    "Deny", 
	}, 
) 
 
client.CreateChannelType(newChannelType
If not provided, the permission settings will default to the ones from the built-in "messaging" type.

Please note that applications have a hard limit of 50 channel types. If you need more than this please have a look at the Multi-tenant & Teams section.

List Channel Types

Copied!

You can retrieve the list of all channel types defined for your application.

1
const channelTypes = await client.listChannelTypes();
1
$types = $client->listChannelTypes();
1
client.list_channel_types()
1
client.ListChannelTypes()

Get a Channel Type

Copied!

You can retrieve a channel type definition with this endpoint. Note: features and commands are also returned by other channel endpoints.

1
const channelType = await client.getChannelType('public');
1
$type = $client->getChannelType('public');
1
client.get_channel_type("public")
1
client.GetChannelType("public")

Edit a Channel Type

Copied!

Channel type features, commands and permissions can be changed. Only the fields that must change need to be provided, fields that are not provided to this API will remain unchanged.

1
2
3
4
const update = await client.updateChannelType('public', { 
    replies: false, 
    commands: ["all"] 
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$update = $client->updateChannelType('public', [ 
    'permissions' => [ 
		[ 
		    'name' => 'Allow reads for all - updated', 
    	          'priority' => 999, 
		    'resources' => ['*'], 
		    'action' => 'Allow', 
		], 
		[ 
			'name' => 'Deny all - updated',  
			'priority' => 1,  
			'resources' => ['*'],  
			'action' => 'Deny' 
		] 
    ], 
    'replies' => false, 
    'commands' => ['all'] 
]);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
client.update_channel_type( 
    "public", 
    permissions=[ 
        dict( 
            name="Allow reads for all", 
            priority=999, 
            resources=["ReadChannel", "CreateMessage"], 
            role="*", 
            action="Allow", 
        ), 
        dict( 
            name="Deny all", 
            priority=1, 
            resources=["*"], 
            role="*", 
            action="Deny", 
        ), 
    ], 
    replies=False, 
    commands=["all"], 
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
client.UpdateChannelType("public", map[string]interface{}{ 
	"permissions": []map[string]interface{}{ 
		map[string]interface{}{ 
			"name":      "Allow reads for all", 
			"priority":  999, 
			"resources": []string{"ReadChannel", "CreateMessage"}, 
			"role":      "*", 
			"action":    "Allow", 
		}, 
		map[string]interface{}{ 
			"name":      "Deny all", 
			"priority":  1, 
			"resources": []string{"*"}, 
			"role":      "*", 
			"action":    "Deny", 
		}, 
	}, 
	"replies":  false, 
	"commands": []string{"all"}, 
})

Features of a channel can be updated by passing the boolean flags:

1
2
3
4
5
6
7
8
9
const update = await client.updateChannelType("public", { 
    typing_events: false, 
    read_events: true, 
    connect_events: true, 
    search: false, 
    reactions: true, 
    replies: false, 
    mutes: true 
});
1
2
3
4
5
6
7
8
9
10
$update = $client->updateChannelType('public', [ 
    'typing_events' => false, 
    'read_events' => true, 
    'connect_events' => true, 
    'search' => false, 
    'reactions' => true, 
    'replies' => false, 
    'mutes' => true, 
    'replies' => false 
]);
1
2
3
4
5
6
7
8
9
client.update_channel_type("public",  
    typing_events=False, 
    read_events=True, 
    connect_events=True, 
    search=False, 
    reactions=True, 
    replies=False, 
    mutes=True 
)
1
2
3
4
5
6
7
8
9
client.UpdateChannelType("public", map[string]interface{}{ 
	"typing_events":  false, 
	"read_events":    true, 
	"connect_events": true, 
	"search":         false, 
	"reactions":      true, 
	"replies":        false, 
	"mutes":          true, 
})

Settings can also be updated by passing in the desired new values:

1
2
3
4
5
6
const update = await client.updateChannelType("public", { 
    automod: "disabled", 
    message_retention: "7", 
    max_message_length: 140, 
    commands: ["giphy", "ban"] 
});
1
2
3
4
5
6
$update = $client->updateChannelType('public', [ 
    'automod' => 'disabled', 
    'message_retention' => '7', 
    'max_message_length' => 140, 
    'commands' => [ 'giphy', 'ban'] 
]);
1
2
3
4
5
6
7
client.update_channel_type( 
    "public", 
    automod="disabled", 
    message_retention="7", 
    max_message_length=140, 
    commands=["ban", "unban"], 
)
1
2
3
4
5
6
7
8
9
client.UpdateChannelType( 
	"public", 
	map[string]interface{}{ 
		"automod":            "disabled", 
		"message_retention":  "7", 
		"max_message_length": 140, 
		"commands":           []interface{}{"ban", "unban"}, 
	}, 
)

Remove a Channel Type

Copied!
1
const destroy = await client.deleteChannelType('public');
1
$client->deleteChannelType('public');
1
client.delete_channel_type("public");
1
client.DeleteChannelType("public")
You cannot delete a channel type if there are any active channels of that type.