Repository navigation
Expand file tree
/
Copy pathgroup_call_leave.cpp
More file actions
41 lines (38 loc) · 1.54 KB
/
Copy pathgroup_call_leave.cpp
File metadata and controls
41 lines (38 loc) · 1.54 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
// Sends phone.leaveGroupCall for a call this account joined earlier, from any process. The source is the audio ssrc the
// join payload declared. Nothing about the earlier join is kept between processes, so the caller must supply it.
//
// Environment: TG_API_ID, TG_API_HASH, TG_SESSION (as in group_call_join.cpp)
// Usage: group_call_leave <call_id> <access_hash> <audio_ssrc>
#include <cstdlib>
#include <exception>
#include <iostream>
#include <stdexcept>
#include <string>
#include "cppgram/client.h"
int main(int argc, char** argv) {
if (argc != 4) {
std::cerr << "usage: group_call_leave <call_id> <access_hash> <audio_ssrc>\n";
return 2;
}
try {
const char* id = std::getenv("TG_API_ID");
const char* hash = std::getenv("TG_API_HASH");
const char* session = std::getenv("TG_SESSION");
if (id == nullptr || hash == nullptr || session == nullptr)
throw std::runtime_error("set TG_API_ID, TG_API_HASH and TG_SESSION");
cppgram::ClientOptions options;
options.api_id = std::stoi(id);
options.api_hash = hash;
options.session_path = session;
cppgram::Client client(options);
client.connect();
const cppgram::GroupCallRef call { std::stoll(argv[1]), std::stoll(argv[2]) };
client.leave_group_call(call, std::stoi(argv[3]));
std::cout << "left call " << call.id << "\n";
client.disconnect();
} catch (const std::exception& e) {
std::cerr << "error: " << e.what() << "\n";
return 1;
}
return 0;
}