DEV Community

Cover image for Play With Mattermost

Posted on

Play With Mattermost

Mattermost provides a series of API to interact with the server.

Let's create a service to post Mattermost message daily if we have new orders.

The new order message contains a plaintext message and an Excel file, which is generated by the service as well.

The message contains Emoji, just include them as plaintext.

We have new orders today!! 👏👏

msg := "We have new orders today!! :clap::clap:"

Upload the file first so that the post can include it by adding the file ID. data is the file content.

frsp, rsp := cli.UploadFile(data, chann_id, fd.Name())

Great! Now the file IDs are in frsp, which is a FileUploadResponse. Extract them and save in file_ids.

  post, rsp := cli.CreatePost(&mm.Post{
    FileIds: file_ids,
    ChannelId: chann_id,
    Message: msg,

Then we have a new post on the channel with chann_id, members on that channel can see it. :D

See also

Top comments (0)