commit
eb06a1aa60
13
README.md
13
README.md
@ -29,10 +29,19 @@ func main() {
|
|||||||
Type: "telegram",
|
Type: "telegram",
|
||||||
Events: []string{
|
Events: []string{
|
||||||
"message_sent",
|
"message_sent",
|
||||||
"message_updated",
|
|
||||||
"message_deleted",
|
|
||||||
"message_read",
|
"message_read",
|
||||||
},
|
},
|
||||||
|
Settings: ChannelSettings{
|
||||||
|
ReceiveMessageMode: "always",
|
||||||
|
SpamAllowed: false,
|
||||||
|
Features: ChannelFeatures{
|
||||||
|
StatusDelivered: "none",
|
||||||
|
MessageDeleting: "send",
|
||||||
|
MessageEditing: "both",
|
||||||
|
MessageQuoting: "both",
|
||||||
|
ImageMessage: "receive",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
data, status, err := c.ActivateTransportChannel(ch)
|
data, status, err := c.ActivateTransportChannel(ch)
|
||||||
|
38
v1/client.go
38
v1/client.go
@ -26,7 +26,21 @@ func New(url string, token string) *MgClient {
|
|||||||
//
|
//
|
||||||
// request := ActivateRequest{
|
// request := ActivateRequest{
|
||||||
// Type: "telegram",
|
// Type: "telegram",
|
||||||
// Events: [2]int{"message_sent", "message_sent"}
|
// Events: []string{
|
||||||
|
// "message_sent",
|
||||||
|
// "message_read",
|
||||||
|
// },
|
||||||
|
// Settings: ChannelSettings{
|
||||||
|
// ReceiveMessageMode: "always",
|
||||||
|
// SpamAllowed: false,
|
||||||
|
// Features: ChannelFeatures{
|
||||||
|
// StatusDelivered: "none",
|
||||||
|
// MessageDeleting: "send",
|
||||||
|
// MessageEditing: "both",
|
||||||
|
// MessageQuoting: "both",
|
||||||
|
// ImageMessage: "receive",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// data, status, err := client.ActivateTransportChannel(request)
|
// data, status, err := client.ActivateTransportChannel(request)
|
||||||
@ -65,7 +79,21 @@ func (c *MgClient) ActivateTransportChannel(request Channel) (ActivateResponse,
|
|||||||
// request := ActivateRequest{
|
// request := ActivateRequest{
|
||||||
// ID: 3053450384,
|
// ID: 3053450384,
|
||||||
// Type: "telegram",
|
// Type: "telegram",
|
||||||
// Events: [2]int{"message_sent", "message_sent"}
|
// Events: []string{
|
||||||
|
// "message_sent",
|
||||||
|
// "message_read",
|
||||||
|
// },
|
||||||
|
// Settings: ChannelSettings{
|
||||||
|
// ReceiveMessageMode: "always",
|
||||||
|
// SpamAllowed: false,
|
||||||
|
// Features: ChannelFeatures{
|
||||||
|
// StatusDelivered: "none",
|
||||||
|
// MessageDeleting: "send",
|
||||||
|
// MessageEditing: "both",
|
||||||
|
// MessageQuoting: "both",
|
||||||
|
// ImageMessage: "receive",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// data, status, err := client.UpdateTransportChannel(request)
|
// data, status, err := client.UpdateTransportChannel(request)
|
||||||
@ -192,7 +220,7 @@ func (c *MgClient) Messages(request SendData) (MessagesResponse, int, error) {
|
|||||||
// Type: "text",
|
// Type: "text",
|
||||||
// Text: "hello hello!",
|
// Text: "hello hello!",
|
||||||
// },
|
// },
|
||||||
// time.Now(),
|
// MakeTimestamp(),
|
||||||
// },
|
// },
|
||||||
// 10,
|
// 10,
|
||||||
// }
|
// }
|
||||||
@ -278,3 +306,7 @@ func (c *MgClient) Error(info []byte) error {
|
|||||||
|
|
||||||
return errors.New(values[0].(string))
|
return errors.New(values[0].(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MakeTimestamp() int64 {
|
||||||
|
return time.Now().UnixNano() / (int64(time.Millisecond) / int64(time.Nanosecond))
|
||||||
|
}
|
||||||
|
@ -28,6 +28,17 @@ func TestMgClient_ActivateTransportChannel(t *testing.T) {
|
|||||||
"message_sent",
|
"message_sent",
|
||||||
"message_read",
|
"message_read",
|
||||||
},
|
},
|
||||||
|
Settings: ChannelSettings{
|
||||||
|
ReceiveMessageMode: "always",
|
||||||
|
SpamAllowed: false,
|
||||||
|
Features: ChannelFeatures{
|
||||||
|
StatusDelivered: "none",
|
||||||
|
MessageDeleting: "send",
|
||||||
|
MessageEditing: "both",
|
||||||
|
MessageQuoting: "both",
|
||||||
|
ImageMessage: "receive",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
data, status, err := c.ActivateTransportChannel(ch)
|
data, status, err := c.ActivateTransportChannel(ch)
|
||||||
@ -49,6 +60,17 @@ func TestMgClient_ActivateNewTransportChannel(t *testing.T) {
|
|||||||
"message_deleted",
|
"message_deleted",
|
||||||
"message_read",
|
"message_read",
|
||||||
},
|
},
|
||||||
|
Settings: ChannelSettings{
|
||||||
|
ReceiveMessageMode: "always",
|
||||||
|
SpamAllowed: false,
|
||||||
|
Features: ChannelFeatures{
|
||||||
|
StatusDelivered: "none",
|
||||||
|
MessageDeleting: "send",
|
||||||
|
MessageEditing: "both",
|
||||||
|
MessageQuoting: "both",
|
||||||
|
ImageMessage: "receive",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
data, status, err := c.ActivateTransportChannel(ch)
|
data, status, err := c.ActivateTransportChannel(ch)
|
||||||
@ -82,6 +104,17 @@ func TestMgClient_UpdateTransportChannel(t *testing.T) {
|
|||||||
"message_deleted",
|
"message_deleted",
|
||||||
"message_read",
|
"message_read",
|
||||||
},
|
},
|
||||||
|
Settings: ChannelSettings{
|
||||||
|
ReceiveMessageMode: "always",
|
||||||
|
SpamAllowed: false,
|
||||||
|
Features: ChannelFeatures{
|
||||||
|
StatusDelivered: "none",
|
||||||
|
MessageDeleting: "send",
|
||||||
|
MessageEditing: "both",
|
||||||
|
MessageQuoting: "both",
|
||||||
|
ImageMessage: "receive",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
data, status, err := c.UpdateTransportChannel(ch)
|
data, status, err := c.UpdateTransportChannel(ch)
|
||||||
@ -139,7 +172,7 @@ func TestMgClient_UpdateMessages(t *testing.T) {
|
|||||||
Type: "text",
|
Type: "text",
|
||||||
Text: "hello hello!",
|
Text: "hello hello!",
|
||||||
},
|
},
|
||||||
time.Now(),
|
MakeTimestamp(),
|
||||||
},
|
},
|
||||||
channelId,
|
channelId,
|
||||||
}
|
}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
package v1
|
|
71
v1/types.go
71
v1/types.go
@ -15,9 +15,28 @@ type MgClient struct {
|
|||||||
|
|
||||||
// Channel type
|
// Channel type
|
||||||
type Channel struct {
|
type Channel struct {
|
||||||
ID uint64 `url:"id,omitempty"`
|
ID uint64 `json:"id,omitempty"`
|
||||||
Type string `url:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
Events []string `url:"events,omitempty,brackets"`
|
Events []string `json:"events,omitempty,brackets"`
|
||||||
|
Settings ChannelSettings `json:"settings,omitempty,brackets"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelSettings struct
|
||||||
|
type ChannelSettings struct {
|
||||||
|
Features ChannelFeatures `json:"features"`
|
||||||
|
ReceiveMessageMode string `json:"receive_message_mode"`
|
||||||
|
SpamAllowed bool `json:"spam_allowed"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelFeatures struct
|
||||||
|
type ChannelFeatures struct {
|
||||||
|
StatusDelivered string `json:"status_delivered"`
|
||||||
|
StatusRead string `json:"status_read"`
|
||||||
|
MessageDeleting string `json:"message_deleting"`
|
||||||
|
MessageEditing string `json:"message_editing"`
|
||||||
|
MessageQuoting string `json:"message_quoting"`
|
||||||
|
ImageMessage string `json:"image_message"`
|
||||||
|
FileMessage string `json:"file_message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActivateResponse channel activation response
|
// ActivateResponse channel activation response
|
||||||
@ -40,43 +59,43 @@ type DeleteResponse struct {
|
|||||||
|
|
||||||
// User struct
|
// User struct
|
||||||
type User struct {
|
type User struct {
|
||||||
ExternalID string `url:"external_id" json:"external_id"`
|
ExternalID string `json:"external_id" json:"external_id"`
|
||||||
Nickname string `url:"nickname" json:"nickname"`
|
Nickname string `json:"nickname" json:"nickname"`
|
||||||
Firstname string `url:"first_name,omitempty" json:"first_name"`
|
Firstname string `json:"first_name,omitempty" json:"first_name"`
|
||||||
Lastname string `url:"last_name,omitempty" json:"last_name"`
|
Lastname string `json:"last_name,omitempty" json:"last_name"`
|
||||||
Avatar string `url:"avatar,omitempty" json:"avatar"`
|
Avatar string `json:"avatar,omitempty" json:"avatar"`
|
||||||
ProfileURL string `url:"profile_url,omitempty" json:"profile_url"`
|
ProfileURL string `json:"profile_url,omitempty" json:"profile_url"`
|
||||||
Country string `url:"country,omitempty" json:"country"`
|
Country string `json:"country,omitempty" json:"country"`
|
||||||
Language string `url:"language,omitempty" json:"language"`
|
Language string `json:"language,omitempty" json:"language"`
|
||||||
Phone string `url:"phone,omitempty" json:"phone"`
|
Phone string `json:"phone,omitempty" json:"phone"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Message struct
|
// Message struct
|
||||||
type Message struct {
|
type Message struct {
|
||||||
ExternalID string `url:"external_id" json:"external_id"`
|
ExternalID string `json:"external_id" json:"external_id"`
|
||||||
Type string `url:"type,omitempty" json:"type"`
|
Type string `json:"type,omitempty" json:"type"`
|
||||||
Text string `url:"text,omitempty" json:"text"`
|
Text string `json:"text,omitempty" json:"text"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMessage struct
|
// SendMessage struct
|
||||||
type SendMessage struct {
|
type SendMessage struct {
|
||||||
Message
|
Message
|
||||||
SentAt time.Time `url:"sent_at,omitempty"`
|
SentAt time.Time `json:"sent_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateMessage struct
|
// UpdateMessage struct
|
||||||
type UpdateMessage struct {
|
type UpdateMessage struct {
|
||||||
Message
|
Message
|
||||||
EditedAt time.Time `url:"edited_at,omitempty"`
|
EditedAt int64 `json:"edited_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendData struct
|
// SendData struct
|
||||||
type SendData struct {
|
type SendData struct {
|
||||||
Message SendMessage `url:"message" json:"message"`
|
Message SendMessage `json:"message" json:"message"`
|
||||||
User User `url:"user" json:"user"`
|
User User `json:"user" json:"user"`
|
||||||
Channel uint64 `url:"channel" json:"channel"`
|
Channel uint64 `json:"channel" json:"channel"`
|
||||||
ExternalChatID string `url:"external_chat_id" json:"external_chat_id"`
|
ExternalChatID string `json:"external_chat_id" json:"external_chat_id"`
|
||||||
Quote *SendMessageRequestQuote `url:"quote,omitempty" json:"quote,omitempty"`
|
Quote *SendMessageRequestQuote `json:"quote,omitempty" json:"quote,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SendMessageRequestQuote struct {
|
type SendMessageRequestQuote struct {
|
||||||
@ -85,14 +104,14 @@ type SendMessageRequestQuote struct {
|
|||||||
|
|
||||||
// UpdateData struct
|
// UpdateData struct
|
||||||
type UpdateData struct {
|
type UpdateData struct {
|
||||||
Message UpdateMessage `url:"message"`
|
Message UpdateMessage `json:"message"`
|
||||||
Channel uint64 `url:"channel"`
|
Channel uint64 `json:"channel"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteData struct
|
// DeleteData struct
|
||||||
type DeleteData struct {
|
type DeleteData struct {
|
||||||
Message Message `url:"message"`
|
Message Message `json:"message"`
|
||||||
Channel uint64 `url:"channel"`
|
Channel uint64 `json:"channel"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MessagesResponse message event response
|
// MessagesResponse message event response
|
||||||
|
Loading…
Reference in New Issue
Block a user