diff --git a/README.md b/README.md index a271cdd..344a804 100644 --- a/README.md +++ b/README.md @@ -32,14 +32,14 @@ func main() { "message_read", }, Settings: ChannelSettings{ - ReceiveMessageMode: "always", + ReceiveMessageMode: MsgModeAlways, SpamAllowed: false, Features: ChannelFeatures{ - StatusDelivered: "none", - MessageDeleting: "send", - MessageEditing: "both", - MessageQuoting: "both", - ImageMessage: "receive", + StatusDelivered: ChannelFeatureNone, + MessageDeleting: ChannelFeatureSend, + MessageEditing: ChannelFeatureBoth, + MessageQuoting: ChannelFeatureBoth, + ImageMessage: ChannelFeatureReceive, }, }, } diff --git a/v1/client.go b/v1/client.go index fa3108b..f64cef0 100644 --- a/v1/client.go +++ b/v1/client.go @@ -31,14 +31,14 @@ func New(url string, token string) *MgClient { // "message_read", // }, // Settings: ChannelSettings{ -// ReceiveMessageMode: "always", +// ReceiveMessageMode: MsgModeAlways, // SpamAllowed: false, // Features: ChannelFeatures{ -// StatusDelivered: "none", -// MessageDeleting: "send", -// MessageEditing: "both", -// MessageQuoting: "both", -// ImageMessage: "receive", +// StatusDelivered: ChannelFeatureNone, +// MessageDeleting: ChannelFeatureSend, +// MessageEditing: ChannelFeatureBoth, +// MessageQuoting: ChannelFeatureBoth, +// ImageMessage: ChannelFeatureReceive, // }, // }, // } @@ -84,14 +84,14 @@ func (c *MgClient) ActivateTransportChannel(request Channel) (ActivateResponse, // "message_read", // }, // Settings: ChannelSettings{ -// ReceiveMessageMode: "always", +// ReceiveMessageMode: MsgModeTimeLimited, // SpamAllowed: false, // Features: ChannelFeatures{ -// StatusDelivered: "none", -// MessageDeleting: "send", -// MessageEditing: "both", -// MessageQuoting: "both", -// ImageMessage: "receive", +// StatusDelivered: ChannelFeatureNone, +// MessageDeleting: ChannelFeatureSend, +// MessageEditing: ChannelFeatureBoth, +// MessageQuoting: ChannelFeatureBoth, +// ImageMessage: ChannelFeatureReceive, // }, // }, // } @@ -277,7 +277,7 @@ func (c *MgClient) DeleteMessage(request DeleteData) (MessagesResponse, int, err outgoing, _ := json.Marshal(&request) data, status, err := c.DeleteRequest( - "/messages/", + "/messages", []byte(outgoing), ) if err != nil { diff --git a/v1/client_test.go b/v1/client_test.go index 332c392..b4248af 100644 --- a/v1/client_test.go +++ b/v1/client_test.go @@ -29,14 +29,14 @@ func TestMgClient_ActivateTransportChannel(t *testing.T) { "message_read", }, Settings: ChannelSettings{ - ReceiveMessageMode: "always", + ReceiveMessageMode: MsgModeAlways, SpamAllowed: false, Features: ChannelFeatures{ - StatusDelivered: "none", - MessageDeleting: "send", - MessageEditing: "both", - MessageQuoting: "both", - ImageMessage: "receive", + StatusDelivered: ChannelFeatureNone, + MessageDeleting: ChannelFeatureSend, + MessageEditing: ChannelFeatureBoth, + MessageQuoting: ChannelFeatureBoth, + ImageMessage: ChannelFeatureReceive, }, }, } @@ -61,14 +61,14 @@ func TestMgClient_ActivateNewTransportChannel(t *testing.T) { "message_read", }, Settings: ChannelSettings{ - ReceiveMessageMode: "always", + ReceiveMessageMode: MsgModeTimeLimited, SpamAllowed: false, Features: ChannelFeatures{ - StatusDelivered: "none", - MessageDeleting: "send", - MessageEditing: "both", - MessageQuoting: "both", - ImageMessage: "receive", + StatusDelivered: ChannelFeatureNone, + MessageDeleting: ChannelFeatureSend, + MessageEditing: ChannelFeatureBoth, + MessageQuoting: ChannelFeatureBoth, + ImageMessage: ChannelFeatureReceive, }, }, } @@ -108,11 +108,11 @@ func TestMgClient_UpdateTransportChannel(t *testing.T) { ReceiveMessageMode: "always", SpamAllowed: false, Features: ChannelFeatures{ - StatusDelivered: "none", - MessageDeleting: "send", - MessageEditing: "both", - MessageQuoting: "both", - ImageMessage: "receive", + StatusDelivered: ChannelFeatureNone, + MessageDeleting: ChannelFeatureSend, + MessageEditing: ChannelFeatureBoth, + MessageQuoting: ChannelFeatureBoth, + ImageMessage: ChannelFeatureReceive, }, }, } diff --git a/v1/types.go b/v1/types.go index efe8ee8..5a5982f 100644 --- a/v1/types.go +++ b/v1/types.go @@ -5,6 +5,17 @@ import ( "time" ) +const ( + ChannelFeatureNone string = "none" + ChannelFeatureReceive string = "receive" + ChannelFeatureSend string = "send" + ChannelFeatureBoth string = "both" + + MsgModeNever string = "never" + MsgModeTimeLimited string = "time-limited" + MsgModeAlways string = "always" +) + // MgClient type type MgClient struct { URL string `json:"url"` @@ -59,22 +70,22 @@ type DeleteResponse struct { // User struct type User struct { - ExternalID string `json:"external_id" json:"external_id"` - Nickname string `json:"nickname" json:"nickname"` - Firstname string `json:"first_name,omitempty" json:"first_name"` - Lastname string `json:"last_name,omitempty" json:"last_name"` - Avatar string `json:"avatar,omitempty" json:"avatar"` - ProfileURL string `json:"profile_url,omitempty" json:"profile_url"` - Country string `json:"country,omitempty" json:"country"` - Language string `json:"language,omitempty" json:"language"` - Phone string `json:"phone,omitempty" json:"phone"` + ExternalID string `json:"external_id"` + Nickname string `json:"nickname"` + Firstname string `json:"first_name,omitempty"` + Lastname string `json:"last_name,omitempty"` + Avatar string `json:"avatar,omitempty"` + ProfileURL string `json:"profile_url,omitempty"` + Country string `json:"country,omitempty"` + Language string `json:"language,omitempty"` + Phone string `json:"phone,omitempty"` } // Message struct type Message struct { - ExternalID string `json:"external_id" json:"external_id"` - Type string `json:"type,omitempty" json:"type"` - Text string `json:"text,omitempty" json:"text"` + ExternalID string `json:"external_id"` + Type string `json:"type,omitempty"` + Text string `json:"text,omitempty"` } // SendMessage struct @@ -91,11 +102,11 @@ type UpdateMessage struct { // SendData struct type SendData struct { - Message SendMessage `json:"message" json:"message"` - User User `json:"user" json:"user"` - Channel uint64 `json:"channel" json:"channel"` - ExternalChatID string `json:"external_chat_id" json:"external_chat_id"` - Quote *SendMessageRequestQuote `json:"quote,omitempty" json:"quote,omitempty"` + Message SendMessage `json:"message"` + User User `json:"user"` + Channel uint64 `json:"channel"` + ExternalChatID string `json:"external_chat_id"` + Quote *SendMessageRequestQuote `json:"quote,omitempty"` } type SendMessageRequestQuote struct {