-
Notifications
You must be signed in to change notification settings - Fork 0
/
Message.go
58 lines (49 loc) · 1.62 KB
/
Message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package skylead
import (
"encoding/json"
"fmt"
"net/http"
"strings"
errortools "github.com/leapforce-libraries/go_errortools"
go_http "github.com/leapforce-libraries/go_http"
)
type Message struct {
Id int64 `json:"id"`
Attachments json.RawMessage `json:"attachments"`
LinkedinUserId int64 `json:"linkedinUserId"`
Account int64 `json:"account"`
Thread string `json:"thread"`
Message string `json:"message"`
Receiver int64 `json:"receiver"`
Dashboard int64 `json:"dashboard"`
CampaignId int64 `json:"campaignId"`
SeenAt int64 `json:"seenAt"`
CreatedAt int64 `json:"createdAt"`
MessageStatus string `json:"messageStatus"`
MessageType string `json:"messageType"`
}
type GetMessagesConfig struct {
UserId int64
AccountId int64
ThreadIds []string
}
func (service *Service) GetMessages(config *GetMessagesConfig) (map[string][]Message, *errortools.Error) {
if config == nil {
return nil, errortools.ErrorMessage("config is nil")
}
result := struct {
Result struct {
Items map[string][]Message `json:"items"`
} `json:"result"`
}{}
requestConfig := go_http.RequestConfig{
Method: http.MethodGet,
Url: service.url(fmt.Sprintf("users/%v/accounts/%v/conversations/threads?threads=[\"%s\"]", config.UserId, config.AccountId, strings.Join(config.ThreadIds, "\",\""))),
ResponseModel: &result,
}
_, _, e := service.httpRequest(&requestConfig)
if e != nil {
return nil, e
}
return result.Result.Items, nil
}