In this tutorial, we’ll look at how you can initialize the environment of your newly created Stream Chat application.
•3 months ago
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:
1npm install -g getstream-cli
You can confirm that it's installed correctly by running 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.
You'll notice along the way that you get suggestions for default values where possible - just hit Return to accept these.
If you're not in the default region, see the Multi-region Support page to find the correct URL.
To create a user, run the
stream chat:user:create command, which prompts you for an ID and a role for the user:
You can update existing users to add more details, such as the name and profile image URL using
Pro tip: You can also create your users with the
update command to immediately provide those details, in just one step.
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.
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.
Once you have a channel, you can add members to it using
And of course, you can always check the channel's current status using
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.
Here, you'll be able to list your users and their details.
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.
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
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.
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: