|
5 | 5 | This sample Bot shows how to use the Mattermost [Go driver](https://github.com/mattermost/mattermost-server/blob/master/model/client4.go) to interact with a Mattermost server, listen to events and respond to messages. Documentation for the Go driver can be found [here](https://pkg.go.dev/github.com/mattermost/mattermost-server/v6/model).
|
6 | 6 |
|
7 | 7 | Highlights of APIs used in this sample:
|
8 |
| - - Log in to the Mattermost server |
9 |
| - - Create a channel |
10 |
| - - Modify user attributes |
11 |
| - - Connect and listen to WebSocket events for real-time responses to messages |
12 |
| - - Post a message to a channel |
| 8 | + |
| 9 | +- Log in to the Mattermost server |
| 10 | +- Create a channel |
| 11 | +- Modify user attributes |
| 12 | +- Connect and listen to WebSocket events for real-time responses to messages |
| 13 | +- Post a message to a channel |
13 | 14 |
|
14 | 15 | This Bot Sample was tested with Mattermost server version 7.5.2.
|
15 | 16 |
|
16 | 17 | ## Setup Server Environment
|
17 | 18 |
|
18 | 19 | ### Via Docker And Docker-Compose
|
19 |
| -1 - Ensure [Docker](https://www.docker.com/get-started) and [Docker-Compose](https://docs.docker.com/compose/install/) are installed for your system |
20 | 20 |
|
21 |
| -2 - Run `./add_users.sh`. The login information for the Mattermost client will be printed |
| 21 | +1 - Ensure [Docker](https://www.docker.com/get-started) and [Docker-Compose](https://docs.docker.com/compose/install/) are installed on your system. |
| 22 | + |
| 23 | +2 - Run `docker-compose up -d --build` and the mattermost client will be built and will expose the port `8065` to your system's localhost. |
22 | 24 |
|
23 |
| -3 - Run `docker-compose up -d --build` and the mattermost client will be built and will expose the port `8065` to your system's localhost |
| 25 | +3 - Run `./add_users.sh`. The login information for the Mattermost client will be printed. |
24 | 26 |
|
25 |
| -4 - Get a bot token by logging into your mattermost instance, copy `example.env` to `.env` and fill in the credentials. Alternatively, just provide your credentials as environment variables. |
| 27 | +4 - Log into your mattermost instance using these credentials and create a bot account following [these](https://developers.mattermost.com/integrate/reference/bot-accounts/) instructions. |
| 28 | + |
| 29 | +5 - Copy `example.env` to `.env` and fill in the bot token (obtained from the previous step), team name, etc. Alternatively, just provide your credentials as environment variables. |
26 | 30 |
|
27 | 31 | 5 - Start the Bot.
|
28 | 32 |
|
29 | 33 | ```
|
30 | 34 | make run
|
31 | 35 | ```
|
32 |
| -You can verify the Bot is running when |
33 |
| - - `Server detected and is running version X.Y.Z` appears on the command line. |
34 |
| - - `Mattermost Bot Sample has started running` is posted in the `Debugging For Sample Bot` channel. |
| 36 | + |
| 37 | +You can verify the Bot is running when |
| 38 | + |
| 39 | +- `Logged in to mattermost` appears on the command line. |
| 40 | +- `Hi! I am a bot.` is posted in your specified channel. |
35 | 41 |
|
36 | 42 | See "Test the Bot" for testing instructions
|
| 43 | + |
37 | 44 | ### Via Direct System Install/Setup
|
38 |
| -1 - [Install](http://docs.mattermost.com/install/requirements.html) or [upgrade](https://docs.mattermost.com/administration/upgrade.html) to Mattermost server version 3.10+, and verify that the Mattermost server is running on [http://localhost:8065](http://localhost:8065). |
| 45 | + |
| 46 | +1 - [Install](http://docs.mattermost.com/install/requirements.html) or [upgrade](https://docs.mattermost.com/administration/upgrade.html) to Mattermost server version 3.10+, and verify that the Mattermost server is running on [http://localhost:8065](http://localhost:8065). |
39 | 47 |
|
40 | 48 | On the commands below, if you are running Mattermost server version 5.0 or later, use `./bin/mmctl`. If you are running version 4.10 or earlier, use `./bin/platform`.
|
41 | 49 |
|
42 | 50 | Learn more about the `mmctl` CLI tool in the [Mattermost documentation](https://docs.mattermost.com/administration/mmctl-cli-tool.html).
|
43 | 51 |
|
44 |
| -2 - Create a team for the Bot to run. If you have an existing team, you may skip this step and replace `team_name` with your existing team in subsequent steps. |
| 52 | +2 - Create a team for the Bot to run. If you have an existing team, you may skip this step and replace `botsample` with your existing team in subsequent steps. |
| 53 | + |
45 | 54 | ```
|
46 | 55 | ./bin/mmctl team create --name botsample --display_name "Sample Bot playground" --email "[email protected]"
|
47 | 56 | ```
|
48 |
| -3 - Create the user account the Bot will run as. |
49 |
| -``` |
50 |
| -./bin/mmctl user create --email="[email protected]" --password="Password1!" --username="samplebot" |
51 |
| -``` |
52 |
| -4 - Create a second user, `bill`, which we will use to log in and interact with the Bot. |
| 57 | + |
| 58 | +3 - Create a user, `bill`, which we will use to log in and interact with the Bot. |
| 59 | + |
53 | 60 | ```
|
54 | 61 | ./bin/mmctl user create --email="[email protected]" --password="Password1!" --username="bill"
|
55 | 62 | ```
|
56 |
| -5 - (Optional) Give `bill` `system_admin` permissions. |
| 63 | + |
| 64 | +4 - (Optional) Give `bill` `system_admin` permissions. |
| 65 | + |
57 | 66 | ```
|
58 | 67 | ./bin/mmctl roles system_admin bill
|
59 | 68 | ```
|
60 |
| -6 - Add users to the team |
61 |
| -``` |
62 |
| -./bin/mmctl team add botsample samplebot bill |
63 |
| -``` |
64 |
| -7 - Verify the e-mail address |
65 |
| -``` |
66 |
| -./bin/mmctl user verify samplebot |
67 |
| -``` |
68 |
| -8 - Log in to [http://localhost:8065](http://localhost:8065) as `bill` and verify the account was created successfully. Then, navigate to the `botsample` team you created in step 2 to interact with the Bot. |
| 69 | + |
| 70 | +5 - Log in to [http://localhost:8065](http://localhost:8065) as `bill` and verify the account was created successfully. |
| 71 | + |
| 72 | +6 - Create a bot account following [these](https://developers.mattermost.com/integrate/reference/bot-accounts/) instructions. |
| 73 | + |
| 74 | +7 - Copy `example.env` to `.env` and fill in the bot token (obtained from the previous step), team name, etc. Alternatively, just provide your credentials as environment variables. |
69 | 75 |
|
70 | 76 | ## Setup Bot Development Environment
|
71 | 77 |
|
72 | 78 | 1 - Follow the [Developer Machine Setup](https://docs.mattermost.com/developer/dev-setup.html) instructions to setup the bot development environment.
|
73 | 79 |
|
74 | 80 | 2 - Clone the GitHub repository to run the sample.
|
| 81 | + |
75 | 82 | ```
|
76 | 83 | git clone https://github.com/mattermost/mattermost-bot-sample-golang.git
|
77 | 84 | cd mattermost-bot-sample-golang
|
78 | 85 | ```
|
79 |
| -3 - Get a bot token by logging into your mattermost instance, copy `example.env` to `.env` and fill in the credentials. |
80 | 86 |
|
81 |
| -4 - Start the Bot. |
| 87 | +3 - Log into your mattermost instance using these credentials and create a bot account following [these](https://developers.mattermost.com/integrate/reference/bot-accounts/) instructions. |
| 88 | + |
| 89 | +4 - Copy `example.env` to `.env` and fill in the bot token (obtained from the previous step), team name, etc. Alternatively, just provide your credentials as environment variables. |
| 90 | + |
| 91 | +5 - Run with |
| 92 | + |
82 | 93 | ```
|
83 | 94 | make run
|
84 | 95 | ```
|
85 |
| -You can verify the Bot is running when |
86 |
| - - `Logged in to mattermost` appears on the command line. |
87 |
| - - `Hi! I am a bot.` is posted in the your specified channel. |
| 96 | + |
| 97 | +You can verify the Bot is running when |
| 98 | + |
| 99 | +- `Logged in to mattermost` appears on the command line. |
| 100 | +- `Hi! I am a bot.` is posted in your specified channel. |
88 | 101 |
|
89 | 102 | ## Test the Bot
|
90 | 103 |
|
91 | 104 | 1 - Log in to the Mattermost server as `[email protected]` and `Password1!`.
|
92 | 105 |
|
93 |
| -2 - Join the your specified channel. |
| 106 | +2 - Join your specified channel. |
94 | 107 |
|
95 | 108 | 3 - Post a message in the channel such as `hello?` to see if the Bot responds. You should see a response if the Bot is running.
|
96 | 109 |
|
97 | 110 | ## Stop the Bot
|
98 | 111 |
|
99 |
| -1 - In the terminal window, press `CTRL+C` to stop the bot. You should see `Mattermost Bot Sample has stopped running` posted in the `Debugging For Sample Bot` channel. |
| 112 | +1 - In the terminal window, press `CTRL+C` to stop the bot. |
0 commit comments