Packages

Elixir bot framework for Mattermost

Current section

Files

Jump to
mattermost lib mattermost context.ex
Raw

lib/mattermost/context.ex

defmodule Mattermost.Context do
@moduledoc """
Context passed to every bot callback.
Contains the config needed to make API calls, plus the event-specific
fields (channel, user, post) so handlers can respond without extra lookups.
## Fields
| Field | Description |
|-------------|----------------------------------------------------------|
| `config` | `%Mattermost{}` — connection config with token |
| `channel_id`| The channel where the event occurred (may be nil) |
| `user_id` | The user who triggered the event (may be nil) |
| `post` | The `%Mattermost.Post{}` for message events (may be nil) |
## Example
def handle_message(%Mattermost.Post{text: "help"}, ctx) do
Mattermost.API.reply(ctx, "Commands: ping, status")
end
def handle_command("status", _text, ctx) do
Mattermost.API.send_message(ctx, ctx.channel_id, "All systems go.")
end
"""
use TypedStruct
typedstruct enforce: true do
field(:config, Mattermost.t())
field(:channel_id, String.t() | nil, default: nil)
field(:user_id, String.t() | nil, default: nil)
field(:post, term(), default: nil)
end
end