From b3d1b79436a56d746cbdbcfe0c8ab61610d863d6 Mon Sep 17 00:00:00 2001 From: Amele9 Date: Thu, 4 Apr 2024 12:49:10 +0300 Subject: [PATCH] Added partner methods --- examples/createInstance/main.go | 23 +++++++++++++ pkg/api/api.go | 43 +++++++++++++++++++++++++ pkg/categories/categories.go | 34 +++++++++++++++++++ pkg/categories/methods/account.go | 10 ++++++ pkg/categories/methods/base_category.go | 2 ++ pkg/categories/methods/device.go | 1 + pkg/categories/methods/groups.go | 9 ++++++ pkg/categories/methods/journals.go | 4 +++ pkg/categories/methods/partner.go | 23 +++++++++++++ pkg/categories/methods/queues.go | 2 ++ pkg/categories/methods/read_mark.go | 1 + pkg/categories/methods/receiving.go | 3 ++ pkg/categories/methods/sending.go | 16 +++++++-- pkg/categories/methods/service.go | 8 +++++ 14 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 examples/createInstance/main.go create mode 100644 pkg/categories/methods/partner.go diff --git a/examples/createInstance/main.go b/examples/createInstance/main.go new file mode 100644 index 0000000..8bb067b --- /dev/null +++ b/examples/createInstance/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + + "github.com/green-api/whatsapp-api-client-golang/pkg/api" +) + +func main() { + Partner := api.GreenAPI{ + PartnerToken: "gac.1234567891234567891234567891213456789", + } + + response, err := Partner.Methods().Partner().CreateInstance(map[string]interface{}{ + "stateWebhook": "yes", + "incomingWebhook": "yes", + }) + if err != nil { + fmt.Println(err) + } + + fmt.Println(response) +} diff --git a/pkg/api/api.go b/pkg/api/api.go index 48a9d5e..c1c9825 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -1,6 +1,7 @@ package api import ( + "fmt" "strconv" "strings" @@ -11,6 +12,7 @@ type GreenAPI struct { URL string IDInstance string APITokenInstance string + PartnerToken string } func (a GreenAPI) Methods() categories.GreenAPICategories { @@ -33,6 +35,28 @@ func (a GreenAPI) Request(method, APIMethod string, data map[string]interface{}, return response.(map[string]interface{}), err } +func (a GreenAPI) PartnerRequest(method, APIMethod string, data map[string]interface{}, filePath string) (map[string]interface{}, error) { + url, err := a.getPartnerURL(APIMethod) + if err != nil { + return nil, err + } + + response, err := executeRequest(method, url, data, filePath) + + return response.(map[string]interface{}), err +} + +func (a GreenAPI) ArrayPartnerRequest(method, APIMethod string, data map[string]interface{}, filePath string) ([]interface{}, error) { + url, err := a.getPartnerURL(APIMethod) + if err != nil { + return nil, err + } + + response, err := executeRequest(method, url, data, filePath) + + return response.([]interface{}), err +} + func (a GreenAPI) RawRequest(method, APIMethod string, data map[string]interface{}, filePath string) (interface{}, error) { url := a.getURL(method, APIMethod, data) @@ -75,3 +99,22 @@ func (a GreenAPI) getURL(method, APIMethod string, data map[string]interface{}) return url.String() } + +func (a GreenAPI) getPartnerURL(APIMethod string) (string, error) { + if a.PartnerToken == "" { + return "", fmt.Errorf("error while generating URL: PartnerToken is empty") + } + + var url strings.Builder + + url.WriteString("https://api.green-api.com") + + url.WriteString("/") + url.WriteString("partner") + url.WriteString("/") + url.WriteString(APIMethod) + url.WriteString("/") + url.WriteString(a.PartnerToken) + + return url.String(), nil +} diff --git a/pkg/categories/categories.go b/pkg/categories/categories.go index 3bc0679..0ba2be7 100644 --- a/pkg/categories/categories.go +++ b/pkg/categories/categories.go @@ -6,38 +6,72 @@ type GreenAPICategories struct { GreenAPI methods.GreenAPIInterface } +// Account category presents methods for working with the account. +// https://green-api.com/en/docs/api/account/ func (c GreenAPICategories) Account() methods.AccountCategory { return methods.AccountCategory{GreenAPI: c.GreenAPI} } +// Device category presents methods for working with the device (phone). +// https://green-api.com/en/docs/api/phone/ func (c GreenAPICategories) Device() methods.DeviceCategory { return methods.DeviceCategory{GreenAPI: c.GreenAPI} } +// Groups category presents methods for working with group chats. +// https://green-api.com/en/docs/api/groups/ func (c GreenAPICategories) Groups() methods.GroupsCategory { return methods.GroupsCategory{GreenAPI: c.GreenAPI} } +// Journals present methods for working with incoming and outgoing messages. +// https://green-api.com/en/docs/api/journals/ func (c GreenAPICategories) Journals() methods.JournalsCategory { return methods.JournalsCategory{GreenAPI: c.GreenAPI} } +// Queues category presents methods for working with a messages queue. +// https://green-api.com/en/docs/api/queues/ func (c GreenAPICategories) Queues() methods.QueuesCategory { return methods.QueuesCategory{GreenAPI: c.GreenAPI} } +// ReadMark category presents methods for working with chat read mark. +// https://green-api.com/en/docs/api/marks/ func (c GreenAPICategories) ReadMark() methods.ReadMarkCategory { return methods.ReadMarkCategory{GreenAPI: c.GreenAPI} } +// Receiving category presents methods for working with receiving events. +// https://green-api.com/en/docs/api/receiving/ func (c GreenAPICategories) Receiving() methods.ReceivingCategory { return methods.ReceivingCategory{GreenAPI: c.GreenAPI} } +// Sending category presents methods for sending different messages. +// https://green-api.com/en/docs/api/sending/ func (c GreenAPICategories) Sending() methods.SendingCategory { return methods.SendingCategory{GreenAPI: c.GreenAPI} } +// Service category presents different service methods. +// https://green-api.com/en/docs/api/service/ func (c GreenAPICategories) Service() methods.ServiceCategory { return methods.ServiceCategory{GreenAPI: c.GreenAPI} } + +// Partner category presents exclusive methods for partners. +// The partnership scheme involves deeper integration with the service +// and working with a larger number of instances on your side: +// +// * Instance management via API +// * Postpaid billing system (starting from the second month of operation) +// * Daily billing (for created and not deleted instances) +// * Dedicated support line +// For questions regarding connection to the partnership scheme +// and additional conditions, please contact us via email +// at support@green-api.com or via chat on the website. +// https://green-api.com/en/docs/partners/ +func (c GreenAPICategories) Partner() methods.PartnerCategory { + return methods.PartnerCategory{GreenAPI: c.GreenAPI} +} diff --git a/pkg/categories/methods/account.go b/pkg/categories/methods/account.go index b5b054d..f6232d1 100644 --- a/pkg/categories/methods/account.go +++ b/pkg/categories/methods/account.go @@ -5,16 +5,19 @@ type AccountCategory struct { } // GetSettings is designed to get the current settings of the account. +// https://green-api.com/en/docs/api/account/GetSettings/ func (c AccountCategory) GetSettings() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "getSettings", nil, "") } // GetWaSettings is designed to get information about the WhatsApp account. +// https://green-api.com/en/docs/api/account/GetWaSettings/ func (c AccountCategory) GetWaSettings() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "getWaSettings", nil, "") } // SetSettings is for setting the account settings. +// https://green-api.com/en/docs/api/account/SetSettings/ func (c AccountCategory) SetSettings(parameters map[string]interface{}) (map[string]interface{}, error) { method := "GET" if parameters != nil { @@ -25,37 +28,44 @@ func (c AccountCategory) SetSettings(parameters map[string]interface{}) (map[str } // GetStateInstance is designed to get the state of the account. +// https://green-api.com/en/docs/api/account/GetStateInstance/ func (c AccountCategory) GetStateInstance() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "getStateInstance", nil, "") } // GetStatusInstance is designed to get the socket connection state // of the account instance with WhatsApp. +// https://green-api.com/en/docs/api/account/GetStatusInstance/ func (c AccountCategory) GetStatusInstance() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "getStatusInstance", nil, "") } // Reboot is designed to restart the account. +// https://green-api.com/en/docs/api/account/Reboot/ func (c AccountCategory) Reboot() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "reboot", nil, "") } // Logout is designed to unlogin the account. +// https://green-api.com/en/docs/api/account/Logout/ func (c AccountCategory) Logout() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "logout", nil, "") } // QR is designed to get a QR code. +// https://green-api.com/en/docs/api/account/QR/ func (c AccountCategory) QR() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "qr", nil, "") } // SetProfilePicture is designed to set the avatar of the account. +// https://green-api.com/en/docs/api/account/SetProfilePicture/ func (c AccountCategory) SetProfilePicture(filePath string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "setProfilePicture", nil, filePath) } // GetAuthorizationCode is designed to authorize an instance by phone number. +// https://green-api.com/en/docs/api/account/GetAuthorizationCode/ func (c AccountCategory) GetAuthorizationCode(phoneNumber int) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "getAuthorizationCode", map[string]interface{}{ "phoneNumber": phoneNumber, diff --git a/pkg/categories/methods/base_category.go b/pkg/categories/methods/base_category.go index 63e687b..668da9d 100644 --- a/pkg/categories/methods/base_category.go +++ b/pkg/categories/methods/base_category.go @@ -4,4 +4,6 @@ type GreenAPIInterface interface { Request(method, APIMethod string, data map[string]interface{}, filePath string) (map[string]interface{}, error) RawRequest(method, APIMethod string, data map[string]interface{}, filePath string) (interface{}, error) ArrayRequest(method, APIMethod string, data map[string]interface{}, filePath string) ([]interface{}, error) + PartnerRequest(method, APIMethod string, data map[string]interface{}, filePath string) (map[string]interface{}, error) + ArrayPartnerRequest(method, APIMethod string, data map[string]interface{}, filePath string) ([]interface{}, error) } diff --git a/pkg/categories/methods/device.go b/pkg/categories/methods/device.go index 8a00511..ab8db34 100644 --- a/pkg/categories/methods/device.go +++ b/pkg/categories/methods/device.go @@ -6,6 +6,7 @@ type DeviceCategory struct { // GetDeviceInfo is designed to get information about the device (phone) // on which the WhatsApp Business application is running. +// https://green-api.com/en/docs/api/phone/GetDeviceInfo/ func (c DeviceCategory) GetDeviceInfo() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "getDeviceInfo", nil, "") } diff --git a/pkg/categories/methods/groups.go b/pkg/categories/methods/groups.go index 1046724..b2fb03b 100644 --- a/pkg/categories/methods/groups.go +++ b/pkg/categories/methods/groups.go @@ -5,6 +5,7 @@ type GroupsCategory struct { } // CreateGroup is designed to create a group chat. +// https://green-api.com/en/docs/api/groups/CreateGroup/ func (c GroupsCategory) CreateGroup(groupName string, chatIds []string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "createGroup", map[string]interface{}{ "groupName": groupName, @@ -13,6 +14,7 @@ func (c GroupsCategory) CreateGroup(groupName string, chatIds []string) (map[str } // UpdateGroupName changes the name of the group chat. +// https://green-api.com/en/docs/api/groups/UpdateGroupName/ func (c GroupsCategory) UpdateGroupName(groupId, groupName string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "updateGroupName", map[string]interface{}{ "groupId": groupId, @@ -21,6 +23,7 @@ func (c GroupsCategory) UpdateGroupName(groupId, groupName string) (map[string]i } // GetGroupData gets group chat data. +// https://green-api.com/en/docs/api/groups/GetGroupData/ func (c GroupsCategory) GetGroupData(groupId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "getGroupData", map[string]interface{}{ "groupId": groupId, @@ -28,6 +31,7 @@ func (c GroupsCategory) GetGroupData(groupId string) (map[string]interface{}, er } // AddGroupParticipant adds a participant to the group chat. +// https://green-api.com/en/docs/api/groups/AddGroupParticipant/ func (c GroupsCategory) AddGroupParticipant(groupId, participantChatId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "addGroupParticipant", map[string]interface{}{ "groupId": groupId, @@ -36,6 +40,7 @@ func (c GroupsCategory) AddGroupParticipant(groupId, participantChatId string) ( } // RemoveGroupParticipant removes the participant from the group chat. +// https://green-api.com/en/docs/api/groups/RemoveGroupParticipant/ func (c GroupsCategory) RemoveGroupParticipant(groupId, participantChatId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "removeGroupParticipant", map[string]interface{}{ "groupId": groupId, @@ -44,6 +49,7 @@ func (c GroupsCategory) RemoveGroupParticipant(groupId, participantChatId string } // SetGroupAdmin designates a member of a group chat as an administrator. +// https://green-api.com/en/docs/api/groups/SetGroupAdmin/ func (c GroupsCategory) SetGroupAdmin(groupId, participantChatId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "setGroupAdmin", map[string]interface{}{ "groupId": groupId, @@ -52,6 +58,7 @@ func (c GroupsCategory) SetGroupAdmin(groupId, participantChatId string) (map[st } // RemoveAdmin deprives the participant of group chat administration rights. +// https://green-api.com/en/docs/api/groups/RemoveAdmin/ func (c GroupsCategory) RemoveAdmin(groupId, participantChatId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "removeAdmin", map[string]interface{}{ "groupId": groupId, @@ -60,6 +67,7 @@ func (c GroupsCategory) RemoveAdmin(groupId, participantChatId string) (map[stri } // SetGroupPicture sets the avatar of the group. +// https://green-api.com/en/docs/api/groups/SetGroupPicture/ func (c GroupsCategory) SetGroupPicture(filePath, groupId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "setGroupPicture", map[string]interface{}{ "groupId": groupId, @@ -67,6 +75,7 @@ func (c GroupsCategory) SetGroupPicture(filePath, groupId string) (map[string]in } // LeaveGroup logs the user of the current account out of the group chat. +// https://green-api.com/en/docs/api/groups/LeaveGroup/ func (c GroupsCategory) LeaveGroup(groupId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "leaveGroup", map[string]interface{}{ "groupId": groupId, diff --git a/pkg/categories/methods/journals.go b/pkg/categories/methods/journals.go index 9cffa3d..691b216 100644 --- a/pkg/categories/methods/journals.go +++ b/pkg/categories/methods/journals.go @@ -5,11 +5,13 @@ type JournalsCategory struct { } // GetChatHistory returns the chat message history. +// https://green-api.com/en/docs/api/journals/GetChatHistory/ func (c JournalsCategory) GetChatHistory(parameters map[string]interface{}) ([]interface{}, error) { return c.GreenAPI.ArrayRequest("POST", "getChatHistory", parameters, "") } // GetMessage returns a chat message. +// https://green-api.com/en/docs/api/journals/GetMessage/ func (c JournalsCategory) GetMessage(chatId, idMessage string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "getMessage", map[string]interface{}{ "chatId": chatId, @@ -19,11 +21,13 @@ func (c JournalsCategory) GetMessage(chatId, idMessage string) (map[string]inter // LastIncomingMessages returns the most recent incoming messages // of the account. +// https://green-api.com/en/docs/api/journals/LastIncomingMessages/ func (c JournalsCategory) LastIncomingMessages(parameters map[string]interface{}) ([]interface{}, error) { return c.GreenAPI.ArrayRequest("GET", "lastIncomingMessages", parameters, "") } // LastOutgoingMessages returns the last sent messages of the account. +// https://green-api.com/en/docs/api/journals/LastOutgoingMessages/ func (c JournalsCategory) LastOutgoingMessages(parameters map[string]interface{}) ([]interface{}, error) { return c.GreenAPI.ArrayRequest("GET", "lastOutgoingMessages", parameters, "") } diff --git a/pkg/categories/methods/partner.go b/pkg/categories/methods/partner.go new file mode 100644 index 0000000..6f9d786 --- /dev/null +++ b/pkg/categories/methods/partner.go @@ -0,0 +1,23 @@ +package methods + +type PartnerCategory struct { + GreenAPI GreenAPIInterface +} + +// CreateInstance is aimed to create an instace using partner account. +// https://green-api.com/en/docs/partners/createInstance/ +func (c PartnerCategory) CreateInstance(parameters map[string]interface{}) (map[string]interface{}, error) { + return c.GreenAPI.PartnerRequest("POST", "createInstance", parameters, "") +} + +// DeleteInstanceAccount is aimed to delete an instance using partner account. +// https://green-api.com/en/docs/partners/deleteInstanceAccount/ +func (c PartnerCategory) DeleteInstanceAccount(idInstance int) (map[string]interface{}, error) { + return c.GreenAPI.PartnerRequest("POST", "deleteInstanceAccount", map[string]interface{}{"idInstance": idInstance}, "") +} + +// GetInstances is aimed to get all instances on a partner account. +// https://green-api.com/en/docs/partners/getInstances/ +func (c PartnerCategory) GetInstances() ([]interface{}, error) { + return c.GreenAPI.ArrayPartnerRequest("GET", "getInstances", nil, "") +} diff --git a/pkg/categories/methods/queues.go b/pkg/categories/methods/queues.go index 1808c45..586db99 100644 --- a/pkg/categories/methods/queues.go +++ b/pkg/categories/methods/queues.go @@ -6,11 +6,13 @@ type QueuesCategory struct { // ShowMessagesQueue is designed to get the list of messages // that are in the queue to be sent. +// https://green-api.com/en/docs/api/queues/ShowMessagesQueue/ func (c QueuesCategory) ShowMessagesQueue() ([]interface{}, error) { return c.GreenAPI.ArrayRequest("GET", "showMessagesQueue", nil, "") } // ClearMessagesQueue is designed to clear the queue of messages to be sent. +// https://green-api.com/en/docs/api/queues/ClearMessagesQueue/ func (c QueuesCategory) ClearMessagesQueue() (map[string]interface{}, error) { return c.GreenAPI.Request("GET", "clearMessagesQueue", nil, "") } diff --git a/pkg/categories/methods/read_mark.go b/pkg/categories/methods/read_mark.go index a8763dc..f82cb58 100644 --- a/pkg/categories/methods/read_mark.go +++ b/pkg/categories/methods/read_mark.go @@ -5,6 +5,7 @@ type ReadMarkCategory struct { } // ReadChat is designed to mark chat messages as read. +// https://green-api.com/en/docs/api/marks/ReadChat/ func (c ReadMarkCategory) ReadChat(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "readChat", parameters, "") } diff --git a/pkg/categories/methods/receiving.go b/pkg/categories/methods/receiving.go index 2cc050d..c68c32c 100644 --- a/pkg/categories/methods/receiving.go +++ b/pkg/categories/methods/receiving.go @@ -6,6 +6,7 @@ type ReceivingCategory struct { // ReceiveNotification is designed to receive a single incoming notification // from the notification queue. +// https://green-api.com/en/docs/api/receiving/technology-http-api/ReceiveNotification/ func (c ReceivingCategory) ReceiveNotification() (map[string]interface{}, error) { response, err := c.GreenAPI.RawRequest("GET", "receiveNotification", nil, "") @@ -18,6 +19,7 @@ func (c ReceivingCategory) ReceiveNotification() (map[string]interface{}, error) // DeleteNotification is designed to remove an incoming notification // from the notification queue. +// https://green-api.com/en/docs/api/receiving/technology-http-api/DeleteNotification/ func (c ReceivingCategory) DeleteNotification(receiptId int) (map[string]interface{}, error) { return c.GreenAPI.Request("DELETE", "deleteNotification", map[string]interface{}{ "receiptId": receiptId, @@ -25,6 +27,7 @@ func (c ReceivingCategory) DeleteNotification(receiptId int) (map[string]interfa } // DownloadFile is for downloading received and sent files. +// https://green-api.com/en/docs/api/receiving/files/DownloadFile/ func (c ReceivingCategory) DownloadFile(chatId, idMessage string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "downloadFile", map[string]interface{}{ "chatId": chatId, diff --git a/pkg/categories/methods/sending.go b/pkg/categories/methods/sending.go index 03059b8..df26587 100644 --- a/pkg/categories/methods/sending.go +++ b/pkg/categories/methods/sending.go @@ -5,56 +5,64 @@ type SendingCategory struct { } // SendMessage is designed to send a text message to a personal or group chat. +// https://green-api.com/en/docs/api/sending/SendMessage/ func (c SendingCategory) SendMessage(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "sendMessage", parameters, "") } // SendButtons is designed to send a message with buttons // to a personal or group chat. +// https://green-api.com/en/docs/api/sending/SendButtons/ func (c SendingCategory) SendButtons(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "sendButtons", parameters, "") } // SendTemplateButtons is designed to send a message with interactive buttons // from the list of templates in a personal or group chat. +// https://green-api.com/en/docs/api/sending/SendTemplateButtons/ func (c SendingCategory) SendTemplateButtons(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "sendTemplateButtons", parameters, "") } // SendListMessage is designed to send a message with a selection button // from a list of values to a personal or group chat. +// https://green-api.com/en/docs/api/sending/SendListMessage/ func (c SendingCategory) SendListMessage(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "sendListMessage", parameters, "") } -// SendFileByUpload is designed to send a file loaded through a form (form-data). +// SendFileByUpload is designed to send a file loaded through a form-data. +// https://green-api.com/en/docs/api/sending/SendFileByUpload/ func (c SendingCategory) SendFileByUpload(filePath string, parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "sendFileByUpload", parameters, filePath) } // SendFileByUrl is designed to send a file downloaded via a link. +// https://green-api.com/en/docs/api/sending/SendFileByUrl/ func (c SendingCategory) SendFileByUrl(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "sendFileByUrl", parameters, "") } // SendLocation is designed to send a geolocation message. +// https://green-api.com/en/docs/api/sending/SendLocation/ func (c SendingCategory) SendLocation(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "sendLocation", parameters, "") } // SendContact is for sending a message with a contact. +// https://green-api.com/en/docs/api/sending/SendContact/ func (c SendingCategory) SendContact(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "sendContact", parameters, "") } -// SendLink is designed to send a message with a link -// that will add an image preview, title and description. +// The method is deprecated. Please use SendMessage. func (c SendingCategory) SendLink(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "sendLink", parameters, "") } // ForwardMessages is designed for forwarding messages // to a personal or group chat. +// https://green-api.com/en/docs/api/sending/ForwardMessages/ func (c SendingCategory) ForwardMessages(chatId, chatIdFrom string, messages []string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "forwardMessages", map[string]interface{}{ "chatId": chatId, @@ -65,12 +73,14 @@ func (c SendingCategory) ForwardMessages(chatId, chatIdFrom string, messages []s // UploadFile allows you to upload a file from the local file system, // which can later be sent using the SendFileByUrl method. +// https://green-api.com/en/docs/api/sending/UploadFile/ func (c SendingCategory) UploadFile(filePath string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "uploadFile", nil, filePath) } // SendPoll is designed for sending messages with a poll // to a private or group chat. +// https://green-api.com/en/docs/api/sending/SendPoll/ func (c SendingCategory) SendPoll(parameters map[string]interface{}) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "sendPoll", parameters, "") } diff --git a/pkg/categories/methods/service.go b/pkg/categories/methods/service.go index 853580c..632bb0e 100644 --- a/pkg/categories/methods/service.go +++ b/pkg/categories/methods/service.go @@ -5,6 +5,7 @@ type ServiceCategory struct { } // CheckWhatsapp checks if there is a WhatsApp account on the phone number. +// https://green-api.com/en/docs/api/service/CheckWhatsapp/ func (c ServiceCategory) CheckWhatsapp(phoneNumber int) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "checkWhatsapp", map[string]interface{}{ "phoneNumber": phoneNumber, @@ -12,6 +13,7 @@ func (c ServiceCategory) CheckWhatsapp(phoneNumber int) (map[string]interface{}, } // GetAvatar returns the avatar of the correspondent or group chat. +// https://green-api.com/en/docs/api/service/GetAvatar/ func (c ServiceCategory) GetAvatar(chatId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "getAvatar", map[string]interface{}{ "chatId": chatId, @@ -19,11 +21,13 @@ func (c ServiceCategory) GetAvatar(chatId string) (map[string]interface{}, error } // GetContacts is designed to get a list of contacts of the current account. +// https://green-api.com/en/docs/api/service/GetContacts/ func (c ServiceCategory) GetContacts() ([]interface{}, error) { return c.GreenAPI.ArrayRequest("GET", "getContacts", nil, "") } // GetContactInfo is designed to obtain information about the contact. +// https://green-api.com/en/docs/api/service/GetContactInfo/ func (c ServiceCategory) GetContactInfo(chatId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "getContactInfo", map[string]interface{}{ "chatId": chatId, @@ -31,6 +35,7 @@ func (c ServiceCategory) GetContactInfo(chatId string) (map[string]interface{}, } // DeleteMessage deletes the message from chat. +// https://green-api.com/en/docs/api/service/deleteMessage/ func (c ServiceCategory) DeleteMessage(chatId, idMessage string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "deleteMessage", map[string]interface{}{ "chatId": chatId, @@ -39,6 +44,7 @@ func (c ServiceCategory) DeleteMessage(chatId, idMessage string) (map[string]int } // ArchiveChat archives the chat. +// https://green-api.com/en/docs/api/service/archiveChat/ func (c ServiceCategory) ArchiveChat(chatId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "archiveChat", map[string]interface{}{ "chatId": chatId, @@ -46,6 +52,7 @@ func (c ServiceCategory) ArchiveChat(chatId string) (map[string]interface{}, err } // UnarchiveChat unarchives the chat. +// https://green-api.com/en/docs/api/service/unarchiveChat/ func (c ServiceCategory) UnarchiveChat(chatId string) (map[string]interface{}, error) { return c.GreenAPI.Request("POST", "unarchiveChat", map[string]interface{}{ "chatId": chatId, @@ -54,6 +61,7 @@ func (c ServiceCategory) UnarchiveChat(chatId string) (map[string]interface{}, e // SetDisappearingChat is designed to change the settings // of disappearing messages in chats. +// https://green-api.com/en/docs/api/service/SetDisappearingChat/ func (c ServiceCategory) SetDisappearingChat(parameters map[string]interface{}) (map[string]interface{}, error) { method := "GET" if parameters != nil {