-
Notifications
You must be signed in to change notification settings - Fork 57
/
message.go
82 lines (71 loc) · 1.87 KB
/
message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// SPDX-License-Identifier: Apache-2.0
package models
import (
"time"
"github.com/rs/xid"
)
// Message is the struct of the main data structure being passed around for each message generated.
type Message struct {
ID string
Type MessageType
Service MessageService
ChannelID string
ChannelName string
Input string
Output string
Error string
Timestamp string
ThreadID string
ThreadTimestamp string
BotMentioned bool
DirectMessageOnly bool
Debug bool
IsEphemeral bool
StartTime int64
EndTime int64
Attributes map[string]string
Vars map[string]string
OutputToRooms []string
OutputToUsers []string
Remotes Remotes
SourceLink string
}
// MessageType is used to differentiate between different message types.
type MessageType int
// Supported MessageTypes.
const (
MsgTypeUnknown MessageType = iota
MsgTypeDirect
MsgTypeChannel
MsgTypePrivateChannel
)
// MessageService is used to differentiate between different message services.
type MessageService int
// Supported MessageServices.
const (
MsgServiceUnknown MessageService = iota
MsgServiceChat
MsgServiceCLI
MsgServiceScheduler
)
// GenerateMessageID generates a random ID for a message.
func GenerateMessageID() string {
return xid.New().String()
}
// MessageTimestamp timestamps the message.
func MessageTimestamp() int64 {
return time.Now().Unix()
}
// NewMessage creates a new message with initialized fields.
func NewMessage() Message {
return Message{
ID: GenerateMessageID(),
StartTime: MessageTimestamp(),
Attributes: make(map[string]string),
Vars: make(map[string]string),
OutputToRooms: []string{},
OutputToUsers: []string{},
Debug: false,
IsEphemeral: false,
}
}