summaryrefslogtreecommitdiff
path: root/lib/mattermost/command.rb
blob: b6446935eb6ecd01720ddb8d6376a44af1149477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Mattermost
  class Command < Session
    def self.all(team_id)
      get("/teams/#{team_id}/commands/list_team_commands").parsed_response
    end

    # params should be a hash, which supplies _at least_:
    # - trigger => The slash command, no spaces, cannot start with a /
    # - url => What is the URL to trigger here?
    # - icon_url => Supply a link to the icon
    def self.create(team_id, params)
      command = {
        auto_complete: true,
        auto_complete_desc: 'List all available commands',
        auto_complete_hint: '[help]',
        description: 'Perform common operations on GitLab',
        display_name: 'GitLab',
        method: 'P',
        user_name: 'GitLab',
        trigger: 'gitlab',
      }.merge(params)

      response = post( "/teams/#{team_id}/commands/create", body: command.to_json)

      response.parsed_response['token']
    end
  end
end