MM-26056 Add plugin ability to execute slash command. (#14898)
* Add plugin ability to execute slash command. * A test * Add site url to command args for plugin API * Remove unessiary complexity.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b977017ca7
Коммит
bebff8156b
@@ -37,6 +37,12 @@ type API interface {
|
||||
// Minimum server version: 5.2
|
||||
UnregisterCommand(teamId, trigger string) error
|
||||
|
||||
// ExecuteSlashCommand executes a slash command with the given parameters.
|
||||
//
|
||||
// @tag Command
|
||||
// Minimum server version: 5.26
|
||||
ExecuteSlashCommand(commandArgs *model.CommandArgs) (*model.CommandResponse, error)
|
||||
|
||||
// GetSession returns the session object for the Session ID
|
||||
//
|
||||
// Minimum server version: 5.2
|
||||
|
||||
@@ -49,6 +49,13 @@ func (api *apiTimerLayer) UnregisterCommand(teamId, trigger string) error {
|
||||
return _returnsA
|
||||
}
|
||||
|
||||
func (api *apiTimerLayer) ExecuteSlashCommand(commandArgs *model.CommandArgs) (*model.CommandResponse, error) {
|
||||
startTime := timePkg.Now()
|
||||
_returnsA, _returnsB := api.apiImpl.ExecuteSlashCommand(commandArgs)
|
||||
api.recordTime(startTime, "ExecuteSlashCommand", _returnsB == nil)
|
||||
return _returnsA, _returnsB
|
||||
}
|
||||
|
||||
func (api *apiTimerLayer) GetSession(sessionId string) (*model.Session, *model.AppError) {
|
||||
startTime := timePkg.Now()
|
||||
_returnsA, _returnsB := api.apiImpl.GetSession(sessionId)
|
||||
|
||||
@@ -523,6 +523,36 @@ func (s *apiRPCServer) UnregisterCommand(args *Z_UnregisterCommandArgs, returns
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_ExecuteSlashCommandArgs struct {
|
||||
A *model.CommandArgs
|
||||
}
|
||||
|
||||
type Z_ExecuteSlashCommandReturns struct {
|
||||
A *model.CommandResponse
|
||||
B error
|
||||
}
|
||||
|
||||
func (g *apiRPCClient) ExecuteSlashCommand(commandArgs *model.CommandArgs) (*model.CommandResponse, error) {
|
||||
_args := &Z_ExecuteSlashCommandArgs{commandArgs}
|
||||
_returns := &Z_ExecuteSlashCommandReturns{}
|
||||
if err := g.client.Call("Plugin.ExecuteSlashCommand", _args, _returns); err != nil {
|
||||
log.Printf("RPC call to ExecuteSlashCommand API failed: %s", err.Error())
|
||||
}
|
||||
return _returns.A, _returns.B
|
||||
}
|
||||
|
||||
func (s *apiRPCServer) ExecuteSlashCommand(args *Z_ExecuteSlashCommandArgs, returns *Z_ExecuteSlashCommandReturns) error {
|
||||
if hook, ok := s.impl.(interface {
|
||||
ExecuteSlashCommand(commandArgs *model.CommandArgs) (*model.CommandResponse, error)
|
||||
}); ok {
|
||||
returns.A, returns.B = hook.ExecuteSlashCommand(args.A)
|
||||
returns.B = encodableError(returns.B)
|
||||
} else {
|
||||
return encodableError(fmt.Errorf("API ExecuteSlashCommand called but not implemented."))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_GetSessionArgs struct {
|
||||
A string
|
||||
}
|
||||
|
||||
@@ -483,6 +483,29 @@ func (_m *API) EnablePlugin(id string) *model.AppError {
|
||||
return r0
|
||||
}
|
||||
|
||||
// ExecuteSlashCommand provides a mock function with given fields: commandArgs
|
||||
func (_m *API) ExecuteSlashCommand(commandArgs *model.CommandArgs) (*model.CommandResponse, error) {
|
||||
ret := _m.Called(commandArgs)
|
||||
|
||||
var r0 *model.CommandResponse
|
||||
if rf, ok := ret.Get(0).(func(*model.CommandArgs) *model.CommandResponse); ok {
|
||||
r0 = rf(commandArgs)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.CommandResponse)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(*model.CommandArgs) error); ok {
|
||||
r1 = rf(commandArgs)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetBot provides a mock function with given fields: botUserId, includeDeleted
|
||||
func (_m *API) GetBot(botUserId string, includeDeleted bool) (*model.Bot, *model.AppError) {
|
||||
ret := _m.Called(botUserId, includeDeleted)
|
||||
|
||||
Ссылка в новой задаче
Block a user