-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_accaunt.cpp
More file actions
173 lines (153 loc) · 8.72 KB
/
Copy pathtest_accaunt.cpp
File metadata and controls
173 lines (153 loc) · 8.72 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "../include/greenapi.hpp"
/*
* Examples of account methods working
* Rename the function to main to use
* https://green-api.com/en/docs/api/account/
*/
int main_account() {
/*
* Examples of account methods working
* You need to provide your instance details from your personal account.
* Be sure to use the apiUrl and mediaUrl parameters specifically for the higher instance, so you will get the most stable API operation and minimal method response time.
* https://console.green-api.com
*/
greenapi::GreenApi instance1101000001{ "api.green-api.com","api.green-api.com","710701676160","36f20dae0c964139a06f9d8223ea479e3722e557bc234be2a0" };
/*
* Example of using the getSettings method
* The method is aimed for getting the current account settings.
* https://green-api.com/en/docs/api/account/GetSettings/
*/
greenapi::Response getSettings = instance1101000001.account.getSettings();
if (getSettings.error) {
std::cout << "getSettings error: {status code: " << getSettings.status_code << ", request time: " << getSettings.total_time << ", body: " << getSettings.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "instance " + instance1101000001.idInstance + " settings:" << std::endl;
std::cout << "\twid: " << getSettings.bodyJson["wid"] << std::endl;
std::cout << "\tcountryInstance: " << getSettings.bodyJson["countryInstance"] << std::endl;
std::cout << "\ttypeAccount: " << getSettings.bodyJson["typeAccount"] << std::endl;
std::cout << "\twebhookUrl: " << getSettings.bodyJson["webhookUrl"] << std::endl;
std::cout << "\twebhookUrlToken: " << getSettings.bodyJson["webhookUrlToken"] << std::endl;
std::cout << "\tdelaySendMessagesMilliseconds: " << getSettings.bodyJson["delaySendMessagesMilliseconds"] << std::endl;
std::cout << "\tmarkIncomingMessagesReaded: " << getSettings.bodyJson["markIncomingMessagesReaded"] << std::endl;
std::cout << "\tsharedSession: " << getSettings.bodyJson["sharedSession"] << std::endl;
std::cout << "\toutgoingWebhook: " << getSettings.bodyJson["outgoingWebhook"] << std::endl;
std::cout << "\toutgoingMessageWebhook: " << getSettings.bodyJson["outgoingMessageWebhook"] << std::endl;
std::cout << "\toutgoingAPIMessageWebhook: " << getSettings.bodyJson["outgoingAPIMessageWebhook"] << std::endl;
std::cout << "\tincomingWebhook: " << getSettings.bodyJson["incomingWebhook"] << std::endl;
std::cout << "\tdeviceWebhook: " << getSettings.bodyJson["deviceWebhook"] << std::endl;
std::cout << "\tstatusInstanceWebhook: " << getSettings.bodyJson["statusInstanceWebhook"] << std::endl;
std::cout << "\tstateWebhook: " << getSettings.bodyJson["stateWebhook"] << std::endl;
std::cout << "\tenableMessagesHistory: " << getSettings.bodyJson["enableMessagesHistory"] << std::endl;
std::cout << "\tkeepOnlineStatus: " << getSettings.bodyJson["keepOnlineStatus"] << std::endl;
std::cout << "\tpollMessageWebhook: " << getSettings.bodyJson["pollMessageWebhook"] << std::endl;
std::cout << "\tincomingBlockWebhook: " << getSettings.bodyJson["incomingBlockWebhook"] << std::endl;
std::cout << "\tincomingCallWebhook: " << getSettings.bodyJson["incomingCallWebhook"] << "\n" << std::endl;
}
/*
* Example of using the setSettings method
* The method is aimed for setting account settings.
* https://green-api.com/en/docs/api/account/SetSettings/
* @param settings - nlohmann::json object with account settings parameters
*/
nlohmann::json settings{
{"delaySendMessagesMilliseconds",1000},
{ "incomingWebhook","yes" }
};
greenapi::Response setSettings = instance1101000001.account.setSettings(settings);
if (setSettings.error) {
std::cout << "setSettings error: {status code: " << setSettings.status_code << ", request time: " << setSettings.total_time << ", body: " << setSettings.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "instance " + instance1101000001.idInstance + " setSettings: " << setSettings.bodyJson["saveSettings"] << "\n" << std::endl;
}
/*
* Example of using the setSettings method
* The method is aimed for getting the account state.
* https://green-api.com/en/docs/api/account/GetStateInstance/
*/
greenapi::Response stateInstance = instance1101000001.account.getStateInstance();
if (stateInstance.error) {
std::cout << "stateInstance error: {status code: " << stateInstance.status_code << ", request time: " << stateInstance.total_time << ", body: " << stateInstance.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "instance " + instance1101000001.idInstance + " stateInstance: " << stateInstance.bodyJson["stateInstance"] << "\n" << std::endl;
}
/*
* Example of using the reboot method
* The method is aimed for rebooting an instance.
* https://green-api.com/en/docs/api/account/Reboot/
*/
greenapi::Response reboot = instance1101000001.account.reboot();
if (reboot.error) {
std::cout << "reboot error: {status code: " << reboot.status_code << ", request time: " << reboot.total_time << ", body: " << reboot.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "instance " + instance1101000001.idInstance + " isReboot: " << reboot.bodyJson["isReboot"] << "\n" << std::endl;
}
/*
* Example of using the logout method
* The example is commented out to prevent your account from being logged out by mistake.
* The method is aimed for logging out an account.
* https://green-api.com/en/docs/api/account/Logout/
*/
greenapi::Response logout = instance1101000001.account.logout();
if (logout.error) {
std::cout << "logout error: {status code: " << logout.status_code << ", request time: " << logout.total_time << ", body: " << logout.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "instance " + instance1101000001.idInstance + " isLogout: " << logout.bodyJson["isLogout"] << "\n" << std::endl;
}
/*
* Example of using the qr method
* The method is aimed for getting QR code. To authorize your account, you have to scan a QR code from application WhatsApp Business on your phone.
* https://green-api.com/en/docs/api/account/QR/
*/
greenapi::Response qr = instance1101000001.account.qr();
if (qr.error) {
std::cout << "qr error: {status code: " << qr.status_code << ", request time: " << qr.total_time << ", body: " << qr.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "instance " + instance1101000001.idInstance + " get QR:" << std::endl;
std::cout << "\ttype: " << qr.bodyJson["type"] << std::endl;
std::cout << "\tmessage: " << qr.bodyJson["message"] << "\n" << std::endl;
}
/*
* Example of using the getAuthorizationCode method
* The method is intended to authorize an instance by phone number. The method is used as an alternative to the QR method.
* https://green-api.com/en/docs/api/account/GetAuthorizationCode/
* @param settings - phone number in the format 71234567890
* To get an example of the phone number format, use the getSettings method
*/
greenapi::Response authorizationCode = instance1101000001.account.getAuthorizationCode(71234567890);
if (authorizationCode.error) {
std::cout << "authorizationCode error: {status code: " << authorizationCode.status_code << ", request time: " << authorizationCode.total_time << ", body: " << authorizationCode.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "instance " + instance1101000001.idInstance + " getAuthorizationCode:" << std::endl;
std::cout << "\tstatus: " << authorizationCode.bodyJson["status"] << std::endl;
std::cout << "\tcode: " << authorizationCode.bodyJson["code"] << "\n" << std::endl;
}
/*
* Example of using the getStateInstanceHistory method
* The method returns the history of instance state changes in chronological order.
* https://green-api.com/en/docs/api/account/GetStateInstanceHistory/
* @param count - number of records to retrieve (default 100)
*/
greenapi::Response getStateInstanceHistory = instance1101000001.account.getStateInstanceHistory();
if (getStateInstanceHistory.error) {
std::cout << "getStateInstanceHistory error: {status code: " << getStateInstanceHistory.status_code << ", request time: " << getStateInstanceHistory.total_time << ", body: " << getStateInstanceHistory.bodyStr << "}" << "\n" << std::endl;
}
else {
if (getStateInstanceHistory.bodyJson.is_array() && !getStateInstanceHistory.bodyJson.empty()) {
std::cout << "instance " + instance1101000001.idInstance + " getStateInstanceHistory:" << std::endl;
std::cout << "\tstateInstance: " << getStateInstanceHistory.bodyJson[0]["stateInstance"] << std::endl;
std::cout << "\ttimestamp: " << getStateInstanceHistory.bodyJson[0]["timestamp"] << std::endl;
std::cout << "\tphoneNumber: " << getStateInstanceHistory.bodyJson[0]["phoneNumber"] << "\n" << std::endl;
}
else {
std::cout << "instance " + instance1101000001.idInstance + " getStateInstanceHistory: " << getStateInstanceHistory.bodyStr << "\n" << std::endl;
}
}
return 0;
}