54 lines
954 B
Go
54 lines
954 B
Go
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
|
|
}
|