本文整理汇总了Golang中github.com/mattermost/platform/model.IncomingWebhookRequest类的典型用法代码示例。如果您正苦于以下问题:Golang IncomingWebhookRequest类的具体用法?Golang IncomingWebhookRequest怎么用?Golang IncomingWebhookRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IncomingWebhookRequest类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: incomingWebhook
func incomingWebhook(c *api.Context, w http.ResponseWriter, r *http.Request) {
if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
c.Err = model.NewAppError("incomingWebhook", "Incoming webhooks have been disabled by the system admin.", "")
c.Err.StatusCode = http.StatusNotImplemented
return
}
params := mux.Vars(r)
id := params["id"]
hchan := api.Srv.Store.Webhook().GetIncoming(id)
r.ParseForm()
var parsedRequest *model.IncomingWebhookRequest
if r.Header.Get("Content-Type") == "application/json" {
parsedRequest = model.IncomingWebhookRequestFromJson(r.Body)
} else {
parsedRequest = model.IncomingWebhookRequestFromJson(strings.NewReader(r.FormValue("payload")))
}
if parsedRequest == nil {
c.Err = model.NewAppError("incomingWebhook", "Unable to parse incoming data", "")
return
}
text := parsedRequest.Text
if len(text) == 0 && parsedRequest.Attachments == nil {
c.Err = model.NewAppError("incomingWebhook", "No text specified", "")
return
}
channelName := parsedRequest.ChannelName
webhookType := parsedRequest.Type
//attachments is in here for slack compatibility
if parsedRequest.Attachments != nil {
if len(parsedRequest.Props) == 0 {
parsedRequest.Props = make(model.StringInterface)
}
parsedRequest.Props["attachments"] = parsedRequest.Attachments
webhookType = model.POST_SLACK_ATTACHMENT
}
var hook *model.IncomingWebhook
if result := <-hchan; result.Err != nil {
c.Err = model.NewAppError("incomingWebhook", "Invalid webhook", "err="+result.Err.Message)
return
} else {
hook = result.Data.(*model.IncomingWebhook)
}
var channel *model.Channel
var cchan store.StoreChannel
if len(channelName) != 0 {
if channelName[0] == '@' {
if result := <-api.Srv.Store.User().GetByUsername(hook.TeamId, channelName[1:]); result.Err != nil {
c.Err = model.NewAppError("incomingWebhook", "Couldn't find the user", "err="+result.Err.Message)
return
} else {
channelName = model.GetDMNameFromIds(result.Data.(*model.User).Id, hook.UserId)
}
} else if channelName[0] == '#' {
channelName = channelName[1:]
}
cchan = api.Srv.Store.Channel().GetByName(hook.TeamId, channelName)
} else {
cchan = api.Srv.Store.Channel().Get(hook.ChannelId)
}
overrideUsername := parsedRequest.Username
overrideIconUrl := parsedRequest.IconURL
if result := <-cchan; result.Err != nil {
c.Err = model.NewAppError("incomingWebhook", "Couldn't find the channel", "err="+result.Err.Message)
return
} else {
channel = result.Data.(*model.Channel)
}
pchan := api.Srv.Store.Channel().CheckPermissionsTo(hook.TeamId, channel.Id, hook.UserId)
// create a mock session
c.Session = model.Session{UserId: hook.UserId, TeamId: hook.TeamId, IsOAuth: false}
if !c.HasPermissionsToChannel(pchan, "createIncomingHook") && channel.Type != model.CHANNEL_OPEN {
c.Err = model.NewAppError("incomingWebhook", "Inappropriate channel permissions", "")
return
}
if _, err := api.CreateWebhookPost(c, channel.Id, text, overrideUsername, overrideIconUrl, parsedRequest.Props, webhookType); err != nil {
c.Err = err
return
}
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte("ok"))
}
开发者ID:simudream,项目名称:platform-1,代码行数:100,代码来源:web.go
示例2: incomingWebhook
func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
c.Err = model.NewLocAppError("incomingWebhook", "web.incoming_webhook.disabled.app_error", nil, "")
c.Err.StatusCode = http.StatusNotImplemented
return
}
params := mux.Vars(r)
id := params["id"]
hchan := Srv.Store.Webhook().GetIncoming(id)
r.ParseForm()
var parsedRequest *model.IncomingWebhookRequest
contentType := r.Header.Get("Content-Type")
if strings.Split(contentType, "; ")[0] == "application/x-www-form-urlencoded" {
parsedRequest = model.IncomingWebhookRequestFromJson(strings.NewReader(r.FormValue("payload")))
} else {
parsedRequest = model.IncomingWebhookRequestFromJson(r.Body)
}
if parsedRequest == nil {
c.Err = model.NewLocAppError("incomingWebhook", "web.incoming_webhook.parse.app_error", nil, "")
return
}
text := parsedRequest.Text
if len(text) == 0 && parsedRequest.Attachments == nil {
c.Err = model.NewLocAppError("incomingWebhook", "web.incoming_webhook.text.app_error", nil, "")
return
}
channelName := parsedRequest.ChannelName
webhookType := parsedRequest.Type
//attachments is in here for slack compatibility
if parsedRequest.Attachments != nil {
if len(parsedRequest.Props) == 0 {
parsedRequest.Props = make(model.StringInterface)
}
parsedRequest.Props["attachments"] = parsedRequest.Attachments
webhookType = model.POST_SLACK_ATTACHMENT
}
var hook *model.IncomingWebhook
if result := <-hchan; result.Err != nil {
c.Err = model.NewLocAppError("incomingWebhook", "web.incoming_webhook.invalid.app_error", nil, "err="+result.Err.Message)
return
} else {
hook = result.Data.(*model.IncomingWebhook)
}
var channel *model.Channel
var cchan store.StoreChannel
if len(channelName) != 0 {
if channelName[0] == '@' {
if result := <-Srv.Store.User().GetByUsername(channelName[1:]); result.Err != nil {
c.Err = model.NewLocAppError("incomingWebhook", "web.incoming_webhook.user.app_error", nil, "err="+result.Err.Message)
return
} else {
channelName = model.GetDMNameFromIds(result.Data.(*model.User).Id, hook.UserId)
}
} else if channelName[0] == '#' {
channelName = channelName[1:]
}
cchan = Srv.Store.Channel().GetByName(hook.TeamId, channelName)
} else {
cchan = Srv.Store.Channel().Get(hook.ChannelId)
}
overrideUsername := parsedRequest.Username
overrideIconUrl := parsedRequest.IconURL
if result := <-cchan; result.Err != nil {
c.Err = model.NewLocAppError("incomingWebhook", "web.incoming_webhook.channel.app_error", nil, "err="+result.Err.Message)
return
} else {
channel = result.Data.(*model.Channel)
}
pchan := Srv.Store.Channel().CheckPermissionsTo(hook.TeamId, channel.Id, hook.UserId)
// create a mock session
c.Session = model.Session{
UserId: hook.UserId,
TeamMembers: []*model.TeamMember{{TeamId: hook.TeamId, UserId: hook.UserId}},
IsOAuth: false,
}
if !c.HasPermissionsToChannel(pchan, "createIncomingHook") && channel.Type != model.CHANNEL_OPEN {
c.Err = model.NewLocAppError("incomingWebhook", "web.incoming_webhook.permissions.app_error", nil, "")
return
}
if _, err := CreateWebhookPost(c, channel.Id, text, overrideUsername, overrideIconUrl, parsedRequest.Props, webhookType); err != nil {
c.Err = err
return
//.........这里部分代码省略.........
开发者ID:carriercomm,项目名称:platform,代码行数:101,代码来源:webhook.go
注:本文中的github.com/mattermost/platform/model.IncomingWebhookRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论