Commit from m3o/m3o action

This commit is contained in:
m3o-actions
2021-11-03 15:16:55 +00:00
parent a3f66cea0b
commit aecab5372c
22 changed files with 679 additions and 471 deletions

View File

@@ -16,36 +16,71 @@ type StreamService struct {
client *client.Client
}
// Publish a message to the stream. Specify a topic to group messages for a specific topic.
func (t *StreamService) Publish(request *PublishRequest) (*PublishResponse, error) {
rsp := &PublishResponse{}
return rsp, t.client.Call("stream", "Publish", request, rsp)
// List all the active channels
func (t *StreamService) ListChannels(request *ListChannelsRequest) (*ListChannelsResponse, error) {
rsp := &ListChannelsResponse{}
return rsp, t.client.Call("stream", "ListChannels", request, rsp)
}
// Subscribe to messages for a given topic.
func (t *StreamService) Subscribe(request *SubscribeRequest) (*SubscribeResponse, error) {
rsp := &SubscribeResponse{}
return rsp, t.client.Call("stream", "Subscribe", request, rsp)
// List messages for a given channel
func (t *StreamService) ListMessages(request *ListMessagesRequest) (*ListMessagesResponse, error) {
rsp := &ListMessagesResponse{}
return rsp, t.client.Call("stream", "ListMessages", request, rsp)
}
type PublishRequest struct {
// The json message to publish
Message map[string]interface{} `json:"message"`
// The topic to publish to
Topic string `json:"topic"`
// SendMessage a message to the stream.
func (t *StreamService) SendMessage(request *SendMessageRequest) (*SendMessageResponse, error) {
rsp := &SendMessageResponse{}
return rsp, t.client.Call("stream", "SendMessage", request, rsp)
}
type PublishResponse struct {
type Channel struct {
// last activity time
LastActive string `json:"lastActive"`
// name of the channel
Name string `json:"name"`
}
type SubscribeRequest struct {
// The topic to subscribe to
Topic string `json:"topic"`
type ListChannelsRequest struct {
}
type SubscribeResponse struct {
// The next json message on the topic
Message map[string]interface{} `json:"message"`
// The topic subscribed to
Topic string `json:"topic"`
type ListChannelsResponse struct {
Channels []Channel `json:"channels"`
}
type ListMessagesRequest struct {
// The channel to subscribe to
Channel string `json:"channel"`
// number of message to return
Limit int32 `json:"limit"`
}
type ListMessagesResponse struct {
// The channel subscribed to
Channel string `json:"channel"`
// Messages are chronological order
Messages []Message `json:"messages"`
}
type Message struct {
// the channel name
Channel string `json:"channel"`
// id of the message
Id string `json:"id"`
// the associated metadata
Metadata map[string]string `json:"metadata"`
// text of the message
Text string `json:"text"`
// time of message creation
Timestamp string `json:"timestamp"`
}
type SendMessageRequest struct {
// The channel to send to
Channel string `json:"channel"`
// The message text to send
Text string `json:"text"`
}
type SendMessageResponse struct {
}