summaryrefslogtreecommitdiffstats
path: root/model/command_webhook.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-08-16 07:17:57 -0500
committerJoram Wilander <jwawilander@gmail.com>2017-08-16 08:17:57 -0400
commitb122381e87577ddfc12b792a3de9121ea830d50e (patch)
tree1487a6a97aa0a928db230b207463e721e56858c9 /model/command_webhook.go
parent5cd45c939406e5af84b0d9a6967683b77100303c (diff)
downloadchat-b122381e87577ddfc12b792a3de9121ea830d50e.tar.gz
chat-b122381e87577ddfc12b792a3de9121ea830d50e.tar.bz2
chat-b122381e87577ddfc12b792a3de9121ea830d50e.zip
PLT-1649: add response_url support for custom slash commands (#6739)
* add response_url support for custom slash commands * pr suggestions * pr update / suggestion * test fix
Diffstat (limited to 'model/command_webhook.go')
-rw-r--r--model/command_webhook.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/model/command_webhook.go b/model/command_webhook.go
new file mode 100644
index 000000000..0b00e00b6
--- /dev/null
+++ b/model/command_webhook.go
@@ -0,0 +1,65 @@
+// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "net/http"
+)
+
+type CommandWebhook struct {
+ Id string
+ CreateAt int64
+ CommandId string
+ UserId string
+ ChannelId string
+ RootId string
+ ParentId string
+ UseCount int
+}
+
+const (
+ COMMAND_WEBHOOK_LIFETIME = 1000 * 60 * 30
+)
+
+func (o *CommandWebhook) PreSave() {
+ if o.Id == "" {
+ o.Id = NewId()
+ }
+
+ if o.CreateAt == 0 {
+ o.CreateAt = GetMillis()
+ }
+}
+
+func (o *CommandWebhook) IsValid() *AppError {
+ if len(o.Id) != 26 {
+ return NewAppError("CommandWebhook.IsValid", "model.command_hook.id.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ if o.CreateAt == 0 {
+ return NewAppError("CommandWebhook.IsValid", "model.command_hook.create_at.app_error", nil, "id="+o.Id, http.StatusBadRequest)
+ }
+
+ if len(o.CommandId) != 26 {
+ return NewAppError("CommandWebhook.IsValid", "model.command_hook.command_id.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ if len(o.UserId) != 26 {
+ return NewAppError("CommandWebhook.IsValid", "model.command_hook.user_id.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ if len(o.ChannelId) != 26 {
+ return NewAppError("CommandWebhook.IsValid", "model.command_hook.channel_id.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ if len(o.RootId) != 0 && len(o.RootId) != 26 {
+ return NewAppError("CommandWebhook.IsValid", "model.command_hook.root_id.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ if len(o.ParentId) != 0 && len(o.ParentId) != 26 {
+ return NewAppError("CommandWebhook.IsValid", "model.command_hook.parent_id.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ return nil
+}