init: Initial commit
This commit is contained in:
53
app/bot/message.go
Normal file
53
app/bot/message.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package bot
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type Message struct {
|
||||
IsGroup bool `json:"isGroup"`
|
||||
ChannelData ChannelData `json:"channelData"`
|
||||
Activity Activity `json:"activity"`
|
||||
}
|
||||
|
||||
type ChannelData struct {
|
||||
Channel Channel `json:"channel"`
|
||||
}
|
||||
|
||||
type Channel struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
type Activity struct {
|
||||
Type string `json:"type"`
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
func NewMessage(isGroup bool, channelData ChannelData, activity Activity) *Message {
|
||||
return &Message{
|
||||
IsGroup: isGroup,
|
||||
ChannelData: channelData,
|
||||
Activity: activity,
|
||||
}
|
||||
}
|
||||
|
||||
func NewTextPost(channelId, text string) *Message {
|
||||
return &Message{
|
||||
IsGroup: true,
|
||||
ChannelData: ChannelData{
|
||||
Channel: Channel{
|
||||
ID: channelId,
|
||||
},
|
||||
},
|
||||
Activity: Activity{
|
||||
Type: "message",
|
||||
Text: text,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Message) ToJSON() (string, error) {
|
||||
jsonBytes, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(jsonBytes), nil
|
||||
}
|
||||
Reference in New Issue
Block a user