-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtgapi.h
More file actions
100 lines (83 loc) · 2 KB
/
tgapi.h
File metadata and controls
100 lines (83 loc) · 2 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
#ifndef TGAPI_H
#define TGAPI_H
#include <stdint.h>
#define URL_PREFIX "https://api.telegram.org/bot"
typedef struct {
// REQUIRED
const char *first_name;
} Tg_User;
typedef int64_t chat_id_t;
typedef struct {
// REQUIRED
chat_id_t id;
} Tg_Chat;
typedef int32_t message_id_t;
typedef struct {
// REQUIRED
message_id_t message_id;
Tg_Chat *chat;
// OPTIONAL
Tg_User *from;
const char *text;
} Tg_Message;
typedef int32_t update_id_t;
typedef struct {
// REQUIRED
update_id_t update_id;
// OPTIONAL
Tg_Message *message;
} Tg_Update;
// TODO: Should Tg_Update_Array be in here?
typedef struct {
Tg_Update **items;
size_t count;
} Tg_Update_Array;
typedef enum {
GET_ME,
GET_UPDATES,
SEND_MESSAGE,
SET_MESSAGE_REACTION,
} Tg_Method;
typedef struct {
char *bot_token;
Tg_Method method;
// REQUIRED for: SEND_MESSAGE, SET_MESSAGE_REACTION
chat_id_t chat_id;
// REQUIRED for: SEND_MESSAGE
char *text;
// REQUIRED for: SET_MESSAGE_REACTION
message_id_t message_id;
} Tg_Method_Call;
Tg_Method_Call new_tg_api_call_get_me(char *bot_token) {
Tg_Method_Call result = {
.bot_token = bot_token,
.method = GET_ME,
};
return result;
}
Tg_Method_Call new_tg_api_call_get_updates(char *bot_token) {
Tg_Method_Call result = {
.bot_token = bot_token,
.method = GET_UPDATES,
};
return result;
}
Tg_Method_Call new_tg_api_call_send_message(char *bot_token, Tg_Chat *chat, char *text) {
Tg_Method_Call result = {
.bot_token = bot_token,
.method = SEND_MESSAGE,
.chat_id = chat->id,
.text = text,
};
return result;
}
Tg_Method_Call new_tg_api_call_set_message_reaction(char *bot_token, Tg_Message *message) {
Tg_Method_Call result = {
.bot_token = bot_token,
.method = SET_MESSAGE_REACTION,
.chat_id = message->chat->id,
.message_id = message->message_id,
};
return result;
}
#endif // TGAPI_H