@@ -52,6 +52,8 @@ func InitCommand(r *mux.Router) {
|
|||||||
|
|
||||||
sr.Handle("/test", ApiAppHandler(testCommand)).Methods("POST")
|
sr.Handle("/test", ApiAppHandler(testCommand)).Methods("POST")
|
||||||
sr.Handle("/test", ApiAppHandler(testCommand)).Methods("GET")
|
sr.Handle("/test", ApiAppHandler(testCommand)).Methods("GET")
|
||||||
|
sr.Handle("/test_e", ApiAppHandler(testEphemeralCommand)).Methods("POST")
|
||||||
|
sr.Handle("/test_e", ApiAppHandler(testEphemeralCommand)).Methods("GET")
|
||||||
}
|
}
|
||||||
|
|
||||||
func listCommands(c *Context, w http.ResponseWriter, r *http.Request) {
|
func listCommands(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -107,9 +109,8 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
provider := GetCommandProvider(trigger)
|
provider := GetCommandProvider(trigger)
|
||||||
|
|
||||||
if provider != nil {
|
if provider != nil {
|
||||||
|
|
||||||
response := provider.DoCommand(c, channelId, message)
|
response := provider.DoCommand(c, channelId, message)
|
||||||
handleResponse(c, w, response, channelId)
|
handleResponse(c, w, response, channelId, provider.GetCommand(c))
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
chanChan := Srv.Store.Channel().Get(channelId)
|
chanChan := Srv.Store.Channel().Get(channelId)
|
||||||
@@ -187,7 +188,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
if response == nil {
|
if response == nil {
|
||||||
c.Err = model.NewLocAppError("command", "api.command.execute_command.failed_empty.app_error", map[string]interface{}{"Trigger": trigger}, "")
|
c.Err = model.NewLocAppError("command", "api.command.execute_command.failed_empty.app_error", map[string]interface{}{"Trigger": trigger}, "")
|
||||||
} else {
|
} else {
|
||||||
handleResponse(c, w, response, channelId)
|
handleResponse(c, w, response, channelId, cmd)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
@@ -205,21 +206,41 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
c.Err = model.NewLocAppError("command", "api.command.execute_command.not_found.app_error", map[string]interface{}{"Trigger": trigger}, "")
|
c.Err = model.NewLocAppError("command", "api.command.execute_command.not_found.app_error", map[string]interface{}{"Trigger": trigger}, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandResponse, channelId string) {
|
func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandResponse, channelId string, cmd *model.Command) {
|
||||||
|
|
||||||
|
post := &model.Post{}
|
||||||
|
post.ChannelId = channelId
|
||||||
|
post.AddProp("from_webhook", "true")
|
||||||
|
|
||||||
|
if utils.Cfg.ServiceSettings.EnablePostUsernameOverride {
|
||||||
|
if len(cmd.Username) != 0 {
|
||||||
|
post.AddProp("override_username", cmd.Username)
|
||||||
|
} else {
|
||||||
|
post.AddProp("override_username", model.DEFAULT_WEBHOOK_USERNAME)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if utils.Cfg.ServiceSettings.EnablePostIconOverride {
|
||||||
|
if len(cmd.IconURL) != 0 {
|
||||||
|
post.AddProp("override_icon_url", cmd.IconURL)
|
||||||
|
} else {
|
||||||
|
post.AddProp("override_icon_url", model.DEFAULT_WEBHOOK_ICON)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if response.ResponseType == model.COMMAND_RESPONSE_TYPE_IN_CHANNEL {
|
if response.ResponseType == model.COMMAND_RESPONSE_TYPE_IN_CHANNEL {
|
||||||
post := &model.Post{}
|
|
||||||
post.ChannelId = channelId
|
|
||||||
post.Message = response.Text
|
post.Message = response.Text
|
||||||
if _, err := CreatePost(c, post, true); err != nil {
|
if _, err := CreatePost(c, post, true); err != nil {
|
||||||
c.Err = model.NewLocAppError("command", "api.command.execute_command.save.app_error", nil, "")
|
c.Err = model.NewLocAppError("command", "api.command.execute_command.save.app_error", nil, "")
|
||||||
}
|
}
|
||||||
} else if response.ResponseType == model.COMMAND_RESPONSE_TYPE_EPHEMERAL {
|
} else if response.ResponseType == model.COMMAND_RESPONSE_TYPE_EPHEMERAL {
|
||||||
// post := &model.Post{}
|
post.Message = response.Text
|
||||||
// post.ChannelId = channelId
|
post.CreateAt = model.GetMillis()
|
||||||
// post.Message = "TODO_EPHEMERAL: " + response.Text
|
SendEphemeralPost(
|
||||||
// if _, err := CreatePost(c, post, true); err != nil {
|
c.Session.TeamId,
|
||||||
// c.Err = model.NewLocAppError("command", "api.command.execute_command.save.app_error", nil, "")
|
c.Session.UserId,
|
||||||
// }
|
post,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write([]byte(response.ToJson()))
|
w.Write([]byte(response.ToJson()))
|
||||||
@@ -399,3 +420,23 @@ func testCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
w.Write([]byte(rc.ToJson()))
|
w.Write([]byte(rc.ToJson()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testEphemeralCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
r.ParseForm()
|
||||||
|
|
||||||
|
msg := ""
|
||||||
|
if r.Method == "POST" {
|
||||||
|
msg = msg + "\ntoken=" + r.FormValue("token")
|
||||||
|
msg = msg + "\nteam_domain=" + r.FormValue("team_domain")
|
||||||
|
} else {
|
||||||
|
body, _ := ioutil.ReadAll(r.Body)
|
||||||
|
msg = string(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
rc := &model.CommandResponse{
|
||||||
|
Text: "test command response " + msg,
|
||||||
|
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Write([]byte(rc.ToJson()))
|
||||||
|
}
|
||||||
|
|||||||
@@ -537,17 +537,11 @@ export default class ManageCommandCmds extends React.Component {
|
|||||||
onChange={this.updateAutoComplete}
|
onChange={this.updateAutoComplete}
|
||||||
/>
|
/>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id='user.settings.cmds.auto_complete_desc_desc'
|
id='user.settings.cmds.auto_complete_help'
|
||||||
defaultMessage='A short description of what this commands does'
|
defaultMessage='Show this command in autocomplete list'
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div className='padding-top'>
|
|
||||||
<FormattedMessage
|
|
||||||
id='user.settings.cmds.auto_complete_help'
|
|
||||||
defaultMessage='Show this command in autocomplete list.'
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div className='padding-top x2'>
|
<div className='padding-top x2'>
|
||||||
<label className='control-label'>
|
<label className='control-label'>
|
||||||
@@ -565,12 +559,6 @@ export default class ManageCommandCmds extends React.Component {
|
|||||||
placeholder={this.props.intl.formatMessage(holders.addAutoCompleteDescPlaceholder)}
|
placeholder={this.props.intl.formatMessage(holders.addAutoCompleteDescPlaceholder)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className='padding-top'>
|
|
||||||
<FormattedMessage
|
|
||||||
id='user.settings.cmds.auto_complete_desc_desc'
|
|
||||||
defaultMessage='A short description of what this commands does'
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div className='padding-top x2'>
|
<div className='padding-top x2'>
|
||||||
<label className='control-label'>
|
<label className='control-label'>
|
||||||
|
|||||||
@@ -1087,7 +1087,6 @@
|
|||||||
"user.settings.cmds.username_desc": "The username to use when overriding the post.",
|
"user.settings.cmds.username_desc": "The username to use when overriding the post.",
|
||||||
"user.settings.cmds.icon_url_desc": "URL to an icon",
|
"user.settings.cmds.icon_url_desc": "URL to an icon",
|
||||||
"user.settings.cmds.trigger_desc": "Word to trigger on",
|
"user.settings.cmds.trigger_desc": "Word to trigger on",
|
||||||
"user.settings.cmds.auto_complete_desc_desc": "A short description of what this commands does",
|
|
||||||
"user.settings.cmds.auto_complete_help": "Show this command in autocomplete list.",
|
"user.settings.cmds.auto_complete_help": "Show this command in autocomplete list.",
|
||||||
"user.settings.cmds.auto_complete_hint_desc": "List parameters to be passed to the command.",
|
"user.settings.cmds.auto_complete_hint_desc": "List parameters to be passed to the command.",
|
||||||
"user.settings.cmds.request_type_desc": "Command request type issued to the callback URL.",
|
"user.settings.cmds.request_type_desc": "Command request type issued to the callback URL.",
|
||||||
|
|||||||
@@ -1074,7 +1074,6 @@
|
|||||||
"user.settings.cmds.auto_complete.yes": "sí",
|
"user.settings.cmds.auto_complete.yes": "sí",
|
||||||
"user.settings.cmds.auto_complete_desc": "Descripción del Auto Completado: ",
|
"user.settings.cmds.auto_complete_desc": "Descripción del Auto Completado: ",
|
||||||
"user.settings.cmds.auto_complete_desc.placeholder": "Una pequeña descripción de que hace el comando.",
|
"user.settings.cmds.auto_complete_desc.placeholder": "Una pequeña descripción de que hace el comando.",
|
||||||
"user.settings.cmds.auto_complete_desc_desc": "Una pequeña descripción de que hace el comando",
|
|
||||||
"user.settings.cmds.auto_complete_help": "Mostrar este comando en la lista de auto completado.",
|
"user.settings.cmds.auto_complete_help": "Mostrar este comando en la lista de auto completado.",
|
||||||
"user.settings.cmds.auto_complete_hint": "Pista de auto completado: ",
|
"user.settings.cmds.auto_complete_hint": "Pista de auto completado: ",
|
||||||
"user.settings.cmds.auto_complete_hint.placeholder": "[código postal]",
|
"user.settings.cmds.auto_complete_hint.placeholder": "[código postal]",
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user