Setting up your Chat environment with Stream CLI

...

In this tutorial, we’ll look at how you can initialize the environment of your newly created Stream Chat application.

Previously, in Get up and Running With Stream Chat, we looked at how to register your organization, and get an API key and secret for your Stream Chat app. Now it's time to create your first users and channels in this environment.

One of the ways of doing that is by using our friendly stream-cli tool. This gives you simple command line access to the Stream APIs, and provides helpful conversational prompts to input your parameters. Let's see how it works!

If you'd like to perform these steps from the Android client SDK instead, check out Your First Steps with Stream Chat on Android!.

Installing the tool

The stream-cli tool is distributed as a yarn package. You can install it easily via npm by running:

Loading code sample...

You can confirm that it's installed correctly by running the stream help command:

The output of the stream help command

To configure your authentication details, run stream config:set. This will prompt you for details such as your API key and secret, which will be used to perform the actions on your behalf.

Running stream config set

You'll notice along the way that you get suggestions for default values where possible - just hit Return to accept these.

Example of a recommended default value

If you're not in the default region, see the Multi-region Support page to find the correct URL.

Creating users

To create a user, run the stream chat:user:create command, which prompts you for an ID and a role for the user:

Creating a new user

You can update existing users to add more details, such as the name and profile image URL using stream chat:user:update.

Updating an existing user

Pro tip: You can also create your users with the update command to immediately provide those details, in just one step.

Creating a user with the update command

You can query already existing objects, for example, you can look up the full details of a user with stream chat:user:get. This is useful not only to check that you've correctly created your users, but also for quickly debugging their state later on.

Querying an existing user

Creating channels

After creating your users, it's time to create channels for them to talk in. The flow here is very similar to what you've used before, just invoke stream chat:channel:create this time.

Creating a new channel

Once you have a channel, you can add members to it using stream chat:channel:add_member.

Adding a member to the channel

And of course, you can always check the channel's current status using stream chat:channel:get.

Checking created data on the dashboard

Having completed the previous steps, you should now have some users and channels available in your Stream Chat app. You can go to the Explorer page of the dashboard to check these out.

Opening the Stream Chat Explorer on the dashboard

Here, you'll be able to list your users and their details.

Looking at the list of users in the Explorer

You also see the list of available channels, and you can dig down into the members inside an individual channel to see that you've correctly added your users to them.

Inspecting the details of a channel in the Explorer

Using command line parameters

Instead of the friendly conversational style, you can input command parameters to the CLI via command line flags. This is useful if you're running the CLI from a script, for example.

To create a user, you can specify their ID with -u, and their role with -r.

stream chat:user:create -u 'monica-geller' -r user

To create a channel, you can pass in the ID, type, and display name:

stream chat:channel:create -c "friends" -t "messaging" -n "Friends"

Check out the full list of chat commands and arguments that the CLI supports to learn more.

Conclusion

That's a wrap! You now have the ability to easily interact with the Stream Chat API via your command line, to create and manage users and channels. The CLI also lets you interact with messages, reactions, user devices, and more. Keep exploring it by visiting its GitHub page.

To move on to creating your own chat app, check out our tutorials for various platforms. Since you now have your own app and users/channels, you can use those details while going through the tutorials!

Other client libraries: