-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_groups.cpp
209 lines (170 loc) · 7.82 KB
/
test_groups.cpp
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include "../include/greenapi.hpp"
/*
* Examples of groups methods working
* Rename the function to main to use
* https://green-api.com/en/docs/api/groups/
*/
int main_groups() {
/*
* Examples of groups 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{ "https://api.green-api.com","https://media.green-api.com","1101123456","87be9e9532fc49748f2a44b9242e55f2e89f4bf97ed6498f80" };
/*
* The method is aimed for creating a group chat. When creating a group, it is required to simulate human work.
* It is required to create a group no more often than 1 group every 5 minutes.
* https://green-api.com/en/docs/api/groups/CreateGroup/
* @param group - parameters of the created group
*/
nlohmann::json groupCreateGroup{
{"groupName","GREEN API test group"},
{"chatIds", {
}
}
};
greenapi::Response createGroup = instance1101000001.groups.createGroup(groupCreateGroup);
if (createGroup.error) {
std::cout << "createGroup error: {status code: " << createGroup.status_code << ", request time: " << createGroup.total_time << ", body: " << createGroup.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "\tcreated: " << createGroup.bodyJson["created"] << "\n" << std::endl;
std::cout << "\tchatId: " << createGroup.bodyJson["chatId"] << "\n" << std::endl;
std::cout << "\tgroupInviteLink: " << createGroup.bodyJson["groupInviteLink"] << "\n" << std::endl;
}
/*
* The method changes a group chat name.
* https://green-api.com/en/docs/api/groups/UpdateGroupName/
* @param group - parameters of the update group
*/
nlohmann::json groupUpdateGroupName{
{"groupId","[email protected]"},
{"groupName","GREEN API rename group"},
};
greenapi::Response updateGroupName = instance1101000001.groups.updateGroupName(groupUpdateGroupName);
if (updateGroupName.error) {
std::cout << "updateGroupName error: {status code: " << updateGroupName.status_code << ", request time: " << updateGroupName.total_time << ", body: " << updateGroupName.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "\tupdateGroupName: " << updateGroupName.bodyJson["updateGroupName"] << "\n" << std::endl;
}
/*
* The method gets group chat data.
* https://green-api.com/en/docs/api/groups/GetGroupData/
* @param group - parameters of the id group
*/
nlohmann::json groupGetGroupData{
{"groupId","[email protected]"}
};
greenapi::Response getGroupData = instance1101000001.groups.getGroupData(groupGetGroupData);
if (getGroupData.error) {
std::cout << "getGroupData error: {status code: " << getGroupData.status_code << ", request time: " << getGroupData.total_time << ", body: " << getGroupData.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "\tgroupData: " << getGroupData.bodyStr << "\n" << std::endl;
std::cout << "\tgroupInviteLink: " << getGroupData.bodyJson["groupInviteLink"] << "\n" << std::endl;
}
/*
* The method removes a participant from a group chat.
* https://green-api.com/en/docs/api/groups/RemoveGroupParticipant/
* @param group - parameters of participants removed from the group
*/
nlohmann::json groupRemoveGroupParticipant{
{"groupId","[email protected]"},
{"participantChatId","[email protected]"}
};
greenapi::Response removeGroupParticipant = instance1101000001.groups.removeGroupParticipant(groupRemoveGroupParticipant);
if (removeGroupParticipant.error) {
std::cout << "removeGroupParticipant error: {status code: " << removeGroupParticipant.status_code << ", request time: " << removeGroupParticipant.total_time << ", body: " << removeGroupParticipant.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "\tremoveParticipant: " << removeGroupParticipant.bodyJson["removeParticipant"] << "\n" << std::endl;
}
/*
* The method adds a participant to a group chat.
* https://green-api.com/en/docs/api/groups/AddGroupParticipant/
* @param group - parameters of participants added to the group
*/
nlohmann::json groupAddGroupParticipant{
{"groupId","[email protected]"},
{"participantChatId","[email protected]"}
};
greenapi::Response addGroupParticipant = instance1101000001.groups.addGroupParticipant(groupAddGroupParticipant);
if (addGroupParticipant.error) {
std::cout << "addGroupParticipant error: {status code: " << addGroupParticipant.status_code << ", request time: " << addGroupParticipant.total_time << ", body: " << addGroupParticipant.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "\taddParticipant: " << addGroupParticipant.bodyJson["addParticipant"] << "\n" << std::endl;
}
/*
* The method sets a group chat participant as an administrator.
* https://green-api.com/en/docs/api/groups/SetGroupAdmin/
* @param group - parameters of participant assigned by the administrator
*/
nlohmann::json groupSetGroupAdmin{
{"groupId","[email protected]"},
{"participantChatId","[email protected]"}
};
greenapi::Response setGroupAdmin = instance1101000001.groups.setGroupAdmin(groupSetGroupAdmin);
if (setGroupAdmin.error) {
std::cout << "setGroupAdmin error: {status code: " << setGroupAdmin.status_code << ", request time: " << setGroupAdmin.total_time << ", body: " << setGroupAdmin.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "\tsetGroupAdmin: " << setGroupAdmin.bodyJson["setGroupAdmin"] << "\n" << std::endl;
}
/*
* The method removes a participant from group chat administration rights.
* https://green-api.com/en/docs/api/groups/RemoveAdmin/
* @param group - parameters of the participant whose administrator rights are taken away
*/
nlohmann::json groupRemoveAdmin{
{"groupId","[email protected]"},
{"participantChatId","[email protected]"}
};
greenapi::Response removeAdmin = instance1101000001.groups.removeAdmin(groupRemoveAdmin);
if (removeAdmin.error) {
std::cout << "removeAdmin error: {status code: " << removeAdmin.status_code << ", request time: " << removeAdmin.total_time << ", body: " << removeAdmin.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "\tremoveAdmin: " << removeAdmin.bodyJson["removeAdmin"] << "\n" << std::endl;
}
/*
* The method sets a group picture.
* https://green-api.com/en/docs/api/groups/SetGroupPicture/
* @param group - parameters for setting the group picture
*/
nlohmann::json file{
{ "file","C:/1.jpg" }
};
nlohmann::json group{
{"groupId","[email protected]"}
};
greenapi::Response setGroupPicture = instance1101000001.groups.setGroupPicture(file, group);
if (setGroupPicture.error) {
std::cout << "setGroupPicture error: {status code: " << setGroupPicture.status_code << ", request time: " << setGroupPicture.total_time << ", body: " << setGroupPicture.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "\tsetGroupPicture: " << setGroupPicture.bodyJson["setGroupPicture"] << "\n" << std::endl;
std::cout << "\turlAvatar: " << setGroupPicture.bodyJson["urlAvatar"] << "\n" << std::endl;
std::cout << "\treason: " << setGroupPicture.bodyJson["reason"] << "\n" << std::endl;
}
/*
* The method makes the current account user leave the group chat.
* https://green-api.com/en/docs/api/groups/LeaveGroup/
* @param group - group parameters for exit
*/
nlohmann::json groupLeaveGroup{
{"groupId","[email protected]"}
};
greenapi::Response leaveGroup = instance1101000001.groups.leaveGroup(groupLeaveGroup);
if (leaveGroup.error) {
std::cout << "leaveGroup error: {status code: " << leaveGroup.status_code << ", request time: " << leaveGroup.total_time << ", body: " << leaveGroup.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "\tleaveGroup: " << leaveGroup.bodyStr << "\n" << std::endl;
}
return 0;
}