-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_groups.cpp
More file actions
211 lines (172 loc) · 7.95 KB
/
Copy pathtest_groups.cpp
File metadata and controls
211 lines (172 loc) · 7.95 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
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
210
211
#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{ "api.green-api.com","api.green-api.com","710701676160","36f20dae0c964139a06f9d8223ea479e3722e557bc234be2a0" };
/*
* 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", {
"71234567890@c.us",
"71234567891@c.us"
}
}
};
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","120363294532719629@g.us"},
{"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","120363294532719629@g.us"}
};
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","120363294532719629@g.us"},
{"participantChatId","71234567890@c.us"}
};
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","120363294532719629@g.us"},
{"participantChatId","71234567890@c.us"}
};
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","120363294532719629@g.us"},
{"participantChatId","71234567890@c.us"}
};
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","120363294532719629@g.us"},
{"participantChatId","71234567890@c.us"}
};
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 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","120363294532719629@g.us"}
};
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;
}
/*
* The method changes group chat settings (participant permissions). Beta version.
* https://green-api.com/en/docs/api/groups/UpdateGroupSettings/
* @param group - group settings parameters
* example json object nlohmann::json group{
{"groupId","120363294532719629@g.us"},
{"allowParticipantsEditGroupSettings", true},
{"allowParticipantsSendMessages", true}
};
*/
nlohmann::json groupUpdateGroupSettings{
{"groupId","120363294532719629@g.us"},
{"allowParticipantsEditGroupSettings", true},
{"allowParticipantsSendMessages", true}
};
greenapi::Response updateGroupSettings = instance1101000001.groups.updateGroupSettings(groupUpdateGroupSettings);
if (updateGroupSettings.error) {
std::cout << "updateGroupSettings error: {status code: " << updateGroupSettings.status_code << ", request time: " << updateGroupSettings.total_time << ", body: " << updateGroupSettings.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "\tupdateGroupSettings: " << updateGroupSettings.bodyJson["updateGroupSettings"] << "\n" << std::endl;
}
return 0;
}