2016-11-13 19:35:47 +00:00
|
|
|
# Base class for Chat services
|
|
|
|
class MattermostChatService < ChatService
|
|
|
|
def title
|
|
|
|
'Mattermost'
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
2016-11-14 11:41:14 +00:00
|
|
|
'Mattermost is an open source, self-hosted Slack-alternative'
|
2016-11-13 19:35:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_param
|
|
|
|
'mattermost'
|
|
|
|
end
|
|
|
|
|
|
|
|
def help
|
|
|
|
'This service allows you to use slash commands with your Mattermost installation.<br/>
|
|
|
|
To setup this Service you need to create a new <b>"Slash commands"</b> in your Mattermost integration panel,
|
|
|
|
and enter the token below.'
|
|
|
|
end
|
|
|
|
|
|
|
|
def fields
|
|
|
|
[
|
|
|
|
{ type: 'text', name: 'token', placeholder: 'https://hooks.slack.com/services/...' }
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def trigger(params)
|
|
|
|
user = ChatNames::FindUserService.new(chat_names, params).execute
|
|
|
|
return authorize_chat_name(params) unless user
|
|
|
|
|
|
|
|
Mattermost::CommandService.new(project, user, params).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def authorize_chat_name(params)
|
|
|
|
url = ChatNames::RequestService.new(service, params).execute
|
|
|
|
|
|
|
|
{
|
|
|
|
response_type: :ephemeral,
|
|
|
|
message: "You are not authorized. Click this [link](#{url}) to authorize."
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|