示例#1
0
func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandResponse, commandArgs *model.CommandArgs, cmd *model.Command, builtIn bool) {
	post := &model.Post{}
	post.ChannelId = commandArgs.ChannelId
	post.RootId = commandArgs.RootId
	post.ParentId = commandArgs.ParentId
	post.UserId = c.Session.UserId

	if !builtIn {
		post.AddProp("from_webhook", "true")
	}

	if utils.Cfg.ServiceSettings.EnablePostUsernameOverride {
		if len(cmd.Username) != 0 {
			post.AddProp("override_username", cmd.Username)
		} else if len(response.Username) != 0 {
			post.AddProp("override_username", response.Username)
		}
	}

	if utils.Cfg.ServiceSettings.EnablePostIconOverride {
		if len(cmd.IconURL) != 0 {
			post.AddProp("override_icon_url", cmd.IconURL)
		} else if len(response.IconURL) != 0 {
			post.AddProp("override_icon_url", response.IconURL)
		} else {
			post.AddProp("override_icon_url", "")
		}
	}

	if _, err := app.CreateCommandPost(post, c.TeamId, response); err != nil {
		l4g.Error(err.Error())
	}

	w.Write([]byte(response.ToJson()))
}
示例#2
0
func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandResponse, commandArgs *model.CommandArgs, cmd *model.Command, builtIn bool) {
	post := &model.Post{}
	post.ChannelId = commandArgs.ChannelId
	post.RootId = commandArgs.RootId
	post.ParentId = commandArgs.ParentId

	if !builtIn {
		post.AddProp("from_webhook", "true")
	}

	if utils.Cfg.ServiceSettings.EnablePostUsernameOverride {
		if len(cmd.Username) != 0 {
			post.AddProp("override_username", cmd.Username)
		} else if len(response.Username) != 0 {
			post.AddProp("override_username", response.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 if len(response.IconURL) != 0 {
			post.AddProp("override_icon_url", response.IconURL)
		} else {
			post.AddProp("override_icon_url", "")
		}
	}

	if response.ResponseType == model.COMMAND_RESPONSE_TYPE_IN_CHANNEL {
		post.Message = response.Text
		post.UserId = c.Session.UserId
		if _, err := CreatePost(c, post, true); err != nil {
			c.Err = model.NewLocAppError("command", "api.command.execute_command.save.app_error", nil, "")
		}
	} else if response.ResponseType == model.COMMAND_RESPONSE_TYPE_EPHEMERAL && response.Text != "" {
		post.Message = response.Text
		post.CreateAt = model.GetMillis()
		post.UserId = c.Session.UserId
		post.ParentId = ""
		SendEphemeralPost(
			c.TeamId,
			c.Session.UserId,
			post,
		)
	}

	w.Write([]byte(response.ToJson()))
}
示例#3
0
func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandResponse, channelId string) {
	if response.ResponseType == model.COMMAND_RESPONSE_TYPE_IN_CHANNEL {
		post := &model.Post{}
		post.ChannelId = channelId
		post.Message = response.Text
		if _, err := CreatePost(c, post, true); err != nil {
			c.Err = model.NewLocAppError("command", "api.command.execute_command.save.app_error", nil, "")
		}
	} else if response.ResponseType == model.COMMAND_RESPONSE_TYPE_EPHEMERAL {
		// post := &model.Post{}
		// post.ChannelId = channelId
		// post.Message = "TODO_EPHEMERAL: " + response.Text
		// if _, err := CreatePost(c, post, true); err != nil {
		// 	c.Err = model.NewLocAppError("command", "api.command.execute_command.save.app_error", nil, "")
		// }
	}

	w.Write([]byte(response.ToJson()))
}