1
0
mirror of synced 2024-11-25 06:26:03 +03:00

Merge pull request #17 from gwinn/master

add transport features
This commit is contained in:
Alex Lushpai 2018-08-16 16:54:44 +03:00 committed by GitHub
commit eb06a1aa60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 125 additions and 33 deletions

View File

@ -29,10 +29,19 @@ func main() {
Type: "telegram",
Events: []string{
"message_sent",
"message_updated",
"message_deleted",
"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)

View File

@ -26,7 +26,21 @@ func New(url string, token string) *MgClient {
//
// request := ActivateRequest{
// 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)
@ -65,7 +79,21 @@ func (c *MgClient) ActivateTransportChannel(request Channel) (ActivateResponse,
// request := ActivateRequest{
// ID: 3053450384,
// 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)
@ -192,7 +220,7 @@ func (c *MgClient) Messages(request SendData) (MessagesResponse, int, error) {
// Type: "text",
// Text: "hello hello!",
// },
// time.Now(),
// MakeTimestamp(),
// },
// 10,
// }
@ -278,3 +306,7 @@ func (c *MgClient) Error(info []byte) error {
return errors.New(values[0].(string))
}
func MakeTimestamp() int64 {
return time.Now().UnixNano() / (int64(time.Millisecond) / int64(time.Nanosecond))
}

View File

@ -28,6 +28,17 @@ func TestMgClient_ActivateTransportChannel(t *testing.T) {
"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 := c.ActivateTransportChannel(ch)
@ -49,6 +60,17 @@ func TestMgClient_ActivateNewTransportChannel(t *testing.T) {
"message_deleted",
"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)
@ -82,6 +104,17 @@ func TestMgClient_UpdateTransportChannel(t *testing.T) {
"message_deleted",
"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)
@ -139,7 +172,7 @@ func TestMgClient_UpdateMessages(t *testing.T) {
Type: "text",
Text: "hello hello!",
},
time.Now(),
MakeTimestamp(),
},
channelId,
}

View File

@ -1 +0,0 @@
package v1

View File

@ -15,9 +15,28 @@ type MgClient struct {
// Channel type
type Channel struct {
ID uint64 `url:"id,omitempty"`
Type string `url:"type,omitempty"`
Events []string `url:"events,omitempty,brackets"`
ID uint64 `json:"id,omitempty"`
Type string `json:"type,omitempty"`
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
@ -40,43 +59,43 @@ type DeleteResponse struct {
// User struct
type User struct {
ExternalID string `url:"external_id" json:"external_id"`
Nickname string `url:"nickname" json:"nickname"`
Firstname string `url:"first_name,omitempty" json:"first_name"`
Lastname string `url:"last_name,omitempty" json:"last_name"`
Avatar string `url:"avatar,omitempty" json:"avatar"`
ProfileURL string `url:"profile_url,omitempty" json:"profile_url"`
Country string `url:"country,omitempty" json:"country"`
Language string `url:"language,omitempty" json:"language"`
Phone string `url:"phone,omitempty" json:"phone"`
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"`
}
// Message struct
type Message struct {
ExternalID string `url:"external_id" json:"external_id"`
Type string `url:"type,omitempty" json:"type"`
Text string `url:"text,omitempty" json:"text"`
ExternalID string `json:"external_id" json:"external_id"`
Type string `json:"type,omitempty" json:"type"`
Text string `json:"text,omitempty" json:"text"`
}
// SendMessage struct
type SendMessage struct {
Message
SentAt time.Time `url:"sent_at,omitempty"`
SentAt time.Time `json:"sent_at,omitempty"`
}
// UpdateMessage struct
type UpdateMessage struct {
Message
EditedAt time.Time `url:"edited_at,omitempty"`
EditedAt int64 `json:"edited_at,omitempty"`
}
// SendData struct
type SendData struct {
Message SendMessage `url:"message" json:"message"`
User User `url:"user" json:"user"`
Channel uint64 `url:"channel" json:"channel"`
ExternalChatID string `url:"external_chat_id" json:"external_chat_id"`
Quote *SendMessageRequestQuote `url:"quote,omitempty" json:"quote,omitempty"`
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"`
}
type SendMessageRequestQuote struct {
@ -85,14 +104,14 @@ type SendMessageRequestQuote struct {
// UpdateData struct
type UpdateData struct {
Message UpdateMessage `url:"message"`
Channel uint64 `url:"channel"`
Message UpdateMessage `json:"message"`
Channel uint64 `json:"channel"`
}
// DeleteData struct
type DeleteData struct {
Message Message `url:"message"`
Channel uint64 `url:"channel"`
Message Message `json:"message"`
Channel uint64 `json:"channel"`
}
// MessagesResponse message event response