@hasna/connectors 1.1.5 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/bin/index.js +1 -1
  2. package/bin/mcp.js +1 -1
  3. package/connectors/connect-gmail/src/api/attachments.ts +143 -0
  4. package/connectors/connect-gmail/src/api/bulk.ts +713 -0
  5. package/connectors/connect-gmail/src/api/client.ts +131 -0
  6. package/connectors/connect-gmail/src/api/drafts.ts +198 -0
  7. package/connectors/connect-gmail/src/api/export.ts +312 -0
  8. package/connectors/connect-gmail/src/api/filters.ts +127 -0
  9. package/connectors/connect-gmail/src/api/index.ts +63 -0
  10. package/connectors/connect-gmail/src/api/labels.ts +123 -0
  11. package/connectors/connect-gmail/src/api/messages.ts +527 -0
  12. package/connectors/connect-gmail/src/api/profile.ts +72 -0
  13. package/connectors/connect-gmail/src/api/threads.ts +85 -0
  14. package/connectors/connect-gmail/src/cli/index.ts +2389 -0
  15. package/connectors/connect-gmail/src/index.ts +30 -0
  16. package/connectors/connect-gmail/src/types/index.ts +202 -0
  17. package/connectors/connect-gmail/src/utils/auth.ts +256 -0
  18. package/connectors/connect-gmail/src/utils/config.ts +466 -0
  19. package/connectors/connect-gmail/src/utils/contacts.ts +147 -0
  20. package/connectors/connect-gmail/src/utils/markdown.ts +119 -0
  21. package/connectors/connect-gmail/src/utils/output.ts +119 -0
  22. package/connectors/connect-gmail/src/utils/settings.ts +87 -0
  23. package/connectors/connect-gmail/tsconfig.json +16 -0
  24. package/connectors/connect-telegram/src/api/bot.ts +223 -0
  25. package/connectors/connect-telegram/src/api/chats.ts +290 -0
  26. package/connectors/connect-telegram/src/api/client.ts +134 -0
  27. package/connectors/connect-telegram/src/api/index.ts +66 -0
  28. package/connectors/connect-telegram/src/api/inline.ts +63 -0
  29. package/connectors/connect-telegram/src/api/messages.ts +781 -0
  30. package/connectors/connect-telegram/src/api/updates.ts +97 -0
  31. package/connectors/connect-telegram/src/cli/index.ts +690 -0
  32. package/connectors/connect-telegram/src/index.ts +22 -0
  33. package/connectors/connect-telegram/src/types/index.ts +617 -0
  34. package/connectors/connect-telegram/src/utils/config.ts +197 -0
  35. package/connectors/connect-telegram/src/utils/output.ts +119 -0
  36. package/connectors/connect-telegram/tsconfig.json +16 -0
  37. package/package.json +1 -1
@@ -0,0 +1,290 @@
1
+ import type { TelegramClient } from './client';
2
+ import type { TelegramChat, TelegramChatMember, TelegramChatPermissions, TelegramUser } from '../types';
3
+
4
+ export interface GetChatOptions {
5
+ chatId: number | string;
6
+ }
7
+
8
+ export interface GetChatMemberOptions {
9
+ chatId: number | string;
10
+ userId: number;
11
+ }
12
+
13
+ export interface GetChatMemberCountOptions {
14
+ chatId: number | string;
15
+ }
16
+
17
+ export interface GetChatAdministratorsOptions {
18
+ chatId: number | string;
19
+ }
20
+
21
+ export interface LeaveChatOptions {
22
+ chatId: number | string;
23
+ }
24
+
25
+ export interface SetChatTitleOptions {
26
+ chatId: number | string;
27
+ title: string;
28
+ }
29
+
30
+ export interface SetChatDescriptionOptions {
31
+ chatId: number | string;
32
+ description?: string;
33
+ }
34
+
35
+ export interface BanChatMemberOptions {
36
+ chatId: number | string;
37
+ userId: number;
38
+ untilDate?: number;
39
+ revokeMessages?: boolean;
40
+ }
41
+
42
+ export interface UnbanChatMemberOptions {
43
+ chatId: number | string;
44
+ userId: number;
45
+ onlyIfBanned?: boolean;
46
+ }
47
+
48
+ export interface ExportChatInviteLinkOptions {
49
+ chatId: number | string;
50
+ }
51
+
52
+ export interface PinChatMessageOptions {
53
+ chatId: number | string;
54
+ messageId: number;
55
+ disableNotification?: boolean;
56
+ }
57
+
58
+ export interface UnpinChatMessageOptions {
59
+ chatId: number | string;
60
+ messageId?: number;
61
+ }
62
+
63
+ export interface UnpinAllChatMessagesOptions {
64
+ chatId: number | string;
65
+ }
66
+
67
+ export interface RestrictChatMemberOptions {
68
+ chatId: number | string;
69
+ userId: number;
70
+ permissions: TelegramChatPermissions;
71
+ useIndependentChatPermissions?: boolean;
72
+ untilDate?: number;
73
+ }
74
+
75
+ export interface PromoteChatMemberOptions {
76
+ chatId: number | string;
77
+ userId: number;
78
+ isAnonymous?: boolean;
79
+ canManageChat?: boolean;
80
+ canDeleteMessages?: boolean;
81
+ canManageVideoChats?: boolean;
82
+ canRestrictMembers?: boolean;
83
+ canPromoteMembers?: boolean;
84
+ canChangeInfo?: boolean;
85
+ canInviteUsers?: boolean;
86
+ canPostMessages?: boolean;
87
+ canEditMessages?: boolean;
88
+ canPinMessages?: boolean;
89
+ canManageTopics?: boolean;
90
+ }
91
+
92
+ /**
93
+ * Telegram Chats API
94
+ */
95
+ export class ChatsApi {
96
+ constructor(private readonly client: TelegramClient) {}
97
+
98
+ /**
99
+ * Get chat information
100
+ */
101
+ async getChat(options: GetChatOptions): Promise<TelegramChat> {
102
+ return this.client.request<TelegramChat>('getChat', {
103
+ params: {
104
+ chat_id: options.chatId,
105
+ },
106
+ });
107
+ }
108
+
109
+ /**
110
+ * Get a chat member
111
+ */
112
+ async getChatMember(options: GetChatMemberOptions): Promise<TelegramChatMember> {
113
+ return this.client.request<TelegramChatMember>('getChatMember', {
114
+ params: {
115
+ chat_id: options.chatId,
116
+ user_id: options.userId,
117
+ },
118
+ });
119
+ }
120
+
121
+ /**
122
+ * Get the number of members in a chat
123
+ */
124
+ async getChatMemberCount(options: GetChatMemberCountOptions): Promise<number> {
125
+ return this.client.request<number>('getChatMemberCount', {
126
+ params: {
127
+ chat_id: options.chatId,
128
+ },
129
+ });
130
+ }
131
+
132
+ /**
133
+ * Get chat administrators
134
+ */
135
+ async getChatAdministrators(options: GetChatAdministratorsOptions): Promise<TelegramChatMember[]> {
136
+ return this.client.request<TelegramChatMember[]>('getChatAdministrators', {
137
+ params: {
138
+ chat_id: options.chatId,
139
+ },
140
+ });
141
+ }
142
+
143
+ /**
144
+ * Leave a chat
145
+ */
146
+ async leaveChat(options: LeaveChatOptions): Promise<boolean> {
147
+ return this.client.request<boolean>('leaveChat', {
148
+ params: {
149
+ chat_id: options.chatId,
150
+ },
151
+ });
152
+ }
153
+
154
+ /**
155
+ * Set chat title (for groups and channels)
156
+ */
157
+ async setChatTitle(options: SetChatTitleOptions): Promise<boolean> {
158
+ return this.client.request<boolean>('setChatTitle', {
159
+ params: {
160
+ chat_id: options.chatId,
161
+ title: options.title,
162
+ },
163
+ });
164
+ }
165
+
166
+ /**
167
+ * Set chat description
168
+ */
169
+ async setChatDescription(options: SetChatDescriptionOptions): Promise<boolean> {
170
+ return this.client.request<boolean>('setChatDescription', {
171
+ params: {
172
+ chat_id: options.chatId,
173
+ description: options.description,
174
+ },
175
+ });
176
+ }
177
+
178
+ /**
179
+ * Ban a user from a chat
180
+ */
181
+ async banChatMember(options: BanChatMemberOptions): Promise<boolean> {
182
+ return this.client.request<boolean>('banChatMember', {
183
+ params: {
184
+ chat_id: options.chatId,
185
+ user_id: options.userId,
186
+ until_date: options.untilDate,
187
+ revoke_messages: options.revokeMessages,
188
+ },
189
+ });
190
+ }
191
+
192
+ /**
193
+ * Unban a user from a chat
194
+ */
195
+ async unbanChatMember(options: UnbanChatMemberOptions): Promise<boolean> {
196
+ return this.client.request<boolean>('unbanChatMember', {
197
+ params: {
198
+ chat_id: options.chatId,
199
+ user_id: options.userId,
200
+ only_if_banned: options.onlyIfBanned,
201
+ },
202
+ });
203
+ }
204
+
205
+ /**
206
+ * Export chat invite link
207
+ */
208
+ async exportChatInviteLink(options: ExportChatInviteLinkOptions): Promise<string> {
209
+ return this.client.request<string>('exportChatInviteLink', {
210
+ params: {
211
+ chat_id: options.chatId,
212
+ },
213
+ });
214
+ }
215
+
216
+ /**
217
+ * Pin a message in a chat
218
+ */
219
+ async pinChatMessage(options: PinChatMessageOptions): Promise<boolean> {
220
+ return this.client.request<boolean>('pinChatMessage', {
221
+ params: {
222
+ chat_id: options.chatId,
223
+ message_id: options.messageId,
224
+ disable_notification: options.disableNotification,
225
+ },
226
+ });
227
+ }
228
+
229
+ /**
230
+ * Unpin a message in a chat
231
+ */
232
+ async unpinChatMessage(options: UnpinChatMessageOptions): Promise<boolean> {
233
+ return this.client.request<boolean>('unpinChatMessage', {
234
+ params: {
235
+ chat_id: options.chatId,
236
+ message_id: options.messageId,
237
+ },
238
+ });
239
+ }
240
+
241
+ /**
242
+ * Unpin all messages in a chat
243
+ */
244
+ async unpinAllChatMessages(options: UnpinAllChatMessagesOptions): Promise<boolean> {
245
+ return this.client.request<boolean>('unpinAllChatMessages', {
246
+ params: {
247
+ chat_id: options.chatId,
248
+ },
249
+ });
250
+ }
251
+
252
+ /**
253
+ * Restrict a chat member
254
+ */
255
+ async restrictChatMember(options: RestrictChatMemberOptions): Promise<boolean> {
256
+ return this.client.request<boolean>('restrictChatMember', {
257
+ body: {
258
+ chat_id: options.chatId,
259
+ user_id: options.userId,
260
+ permissions: options.permissions,
261
+ use_independent_chat_permissions: options.useIndependentChatPermissions,
262
+ until_date: options.untilDate,
263
+ },
264
+ });
265
+ }
266
+
267
+ /**
268
+ * Promote a chat member
269
+ */
270
+ async promoteChatMember(options: PromoteChatMemberOptions): Promise<boolean> {
271
+ return this.client.request<boolean>('promoteChatMember', {
272
+ params: {
273
+ chat_id: options.chatId,
274
+ user_id: options.userId,
275
+ is_anonymous: options.isAnonymous,
276
+ can_manage_chat: options.canManageChat,
277
+ can_delete_messages: options.canDeleteMessages,
278
+ can_manage_video_chats: options.canManageVideoChats,
279
+ can_restrict_members: options.canRestrictMembers,
280
+ can_promote_members: options.canPromoteMembers,
281
+ can_change_info: options.canChangeInfo,
282
+ can_invite_users: options.canInviteUsers,
283
+ can_post_messages: options.canPostMessages,
284
+ can_edit_messages: options.canEditMessages,
285
+ can_pin_messages: options.canPinMessages,
286
+ can_manage_topics: options.canManageTopics,
287
+ },
288
+ });
289
+ }
290
+ }
@@ -0,0 +1,134 @@
1
+ import type { TelegramConfig, TelegramApiResponse } from '../types';
2
+ import { TelegramApiError } from '../types';
3
+
4
+ const TELEGRAM_API_BASE = 'https://api.telegram.org';
5
+
6
+ export interface TelegramRequestOptions {
7
+ method?: 'GET' | 'POST';
8
+ params?: Record<string, string | number | boolean | undefined>;
9
+ body?: Record<string, unknown> | FormData;
10
+ }
11
+
12
+ /**
13
+ * Telegram Bot API Client
14
+ */
15
+ export class TelegramClient {
16
+ private readonly botToken: string;
17
+ private readonly baseUrl: string;
18
+
19
+ constructor(config: TelegramConfig) {
20
+ if (!config.botToken) {
21
+ throw new Error('Telegram Bot Token is required');
22
+ }
23
+ this.botToken = config.botToken;
24
+ this.baseUrl = `${TELEGRAM_API_BASE}/bot${this.botToken}`;
25
+ }
26
+
27
+ /**
28
+ * Make a request to the Telegram Bot API
29
+ */
30
+ async request<T>(
31
+ method: string,
32
+ options: TelegramRequestOptions = {}
33
+ ): Promise<T> {
34
+ const { method: httpMethod = 'POST', params, body } = options;
35
+
36
+ let url = `${this.baseUrl}/${method}`;
37
+
38
+ // Add query params for GET requests
39
+ if (params && httpMethod === 'GET') {
40
+ const searchParams = new URLSearchParams();
41
+ Object.entries(params).forEach(([key, value]) => {
42
+ if (value !== undefined && value !== null && value !== '') {
43
+ searchParams.append(key, String(value));
44
+ }
45
+ });
46
+ const queryString = searchParams.toString();
47
+ if (queryString) {
48
+ url += `?${queryString}`;
49
+ }
50
+ }
51
+
52
+ const headers: Record<string, string> = {};
53
+ let fetchBody: BodyInit | undefined;
54
+
55
+ if (body) {
56
+ if (body instanceof FormData) {
57
+ // Let the browser set the content-type with boundary for FormData
58
+ fetchBody = body;
59
+ } else {
60
+ headers['Content-Type'] = 'application/json';
61
+ fetchBody = JSON.stringify(body);
62
+ }
63
+ } else if (params && httpMethod === 'POST') {
64
+ // For POST without body, send params as JSON body
65
+ headers['Content-Type'] = 'application/json';
66
+ const cleanParams: Record<string, unknown> = {};
67
+ Object.entries(params).forEach(([key, value]) => {
68
+ if (value !== undefined && value !== null && value !== '') {
69
+ cleanParams[key] = value;
70
+ }
71
+ });
72
+ fetchBody = JSON.stringify(cleanParams);
73
+ }
74
+
75
+ const response = await fetch(url, {
76
+ method: httpMethod,
77
+ headers,
78
+ body: fetchBody,
79
+ });
80
+
81
+ const data = await response.json() as TelegramApiResponse<T>;
82
+
83
+ if (!data.ok) {
84
+ throw new TelegramApiError(
85
+ data.description || 'Unknown Telegram API error',
86
+ response.status,
87
+ data.error_code
88
+ );
89
+ }
90
+
91
+ return data.result as T;
92
+ }
93
+
94
+ /**
95
+ * Upload a file to Telegram
96
+ */
97
+ async uploadFile<T>(
98
+ method: string,
99
+ fileField: string,
100
+ fileData: Uint8Array,
101
+ fileName: string,
102
+ additionalParams: Record<string, string | number | boolean | undefined> = {}
103
+ ): Promise<T> {
104
+ const formData = new FormData();
105
+
106
+ // Add the file - create a proper ArrayBuffer from Uint8Array
107
+ const arrayBuffer = fileData.buffer.slice(fileData.byteOffset, fileData.byteOffset + fileData.byteLength) as ArrayBuffer;
108
+ const blob = new Blob([arrayBuffer]);
109
+ formData.append(fileField, blob, fileName);
110
+
111
+ // Add additional params
112
+ Object.entries(additionalParams).forEach(([key, value]) => {
113
+ if (value !== undefined && value !== null && value !== '') {
114
+ formData.append(key, String(value));
115
+ }
116
+ });
117
+
118
+ return this.request<T>(method, { body: formData });
119
+ }
120
+
121
+ /**
122
+ * Get a preview of the bot token (for display/debugging)
123
+ */
124
+ getTokenPreview(): string {
125
+ if (this.botToken.length > 10) {
126
+ const parts = this.botToken.split(':');
127
+ if (parts.length === 2) {
128
+ return `${parts[0]}:****`;
129
+ }
130
+ return `${this.botToken.substring(0, 6)}...`;
131
+ }
132
+ return '***';
133
+ }
134
+ }
@@ -0,0 +1,66 @@
1
+ import type { TelegramConfig } from '../types';
2
+ import { TelegramClient } from './client';
3
+ import { MessagesApi } from './messages';
4
+ import { ChatsApi } from './chats';
5
+ import { UpdatesApi } from './updates';
6
+ import { InlineApi } from './inline';
7
+ import { BotApi } from './bot';
8
+
9
+ /**
10
+ * Main Telegram Connector class
11
+ * Provides access to Telegram Bot API services
12
+ */
13
+ export class Telegram {
14
+ private readonly client: TelegramClient;
15
+
16
+ // Service APIs
17
+ public readonly messages: MessagesApi;
18
+ public readonly chats: ChatsApi;
19
+ public readonly updates: UpdatesApi;
20
+ public readonly inline: InlineApi;
21
+ public readonly bot: BotApi;
22
+
23
+ constructor(config: TelegramConfig) {
24
+ this.client = new TelegramClient(config);
25
+ this.messages = new MessagesApi(this.client);
26
+ this.chats = new ChatsApi(this.client);
27
+ this.updates = new UpdatesApi(this.client);
28
+ this.inline = new InlineApi(this.client);
29
+ this.bot = new BotApi(this.client);
30
+ }
31
+
32
+ /**
33
+ * Create a client from environment variables
34
+ * Looks for TELEGRAM_BOT_TOKEN
35
+ */
36
+ static fromEnv(): Telegram {
37
+ const botToken = process.env.TELEGRAM_BOT_TOKEN;
38
+
39
+ if (!botToken) {
40
+ throw new Error('TELEGRAM_BOT_TOKEN environment variable is required');
41
+ }
42
+
43
+ return new Telegram({ botToken });
44
+ }
45
+
46
+ /**
47
+ * Get a preview of the bot token (for debugging)
48
+ */
49
+ getTokenPreview(): string {
50
+ return this.client.getTokenPreview();
51
+ }
52
+
53
+ /**
54
+ * Get the underlying client for direct API access
55
+ */
56
+ getClient(): TelegramClient {
57
+ return this.client;
58
+ }
59
+ }
60
+
61
+ export { TelegramClient } from './client';
62
+ export { MessagesApi } from './messages';
63
+ export { ChatsApi } from './chats';
64
+ export { UpdatesApi } from './updates';
65
+ export { InlineApi } from './inline';
66
+ export { BotApi } from './bot';
@@ -0,0 +1,63 @@
1
+ import type { TelegramClient } from './client';
2
+ import type { TelegramInlineQueryResult } from '../types';
3
+
4
+ export interface AnswerInlineQueryOptions {
5
+ inlineQueryId: string;
6
+ results: TelegramInlineQueryResult[];
7
+ cacheTime?: number;
8
+ isPersonal?: boolean;
9
+ nextOffset?: string;
10
+ button?: InlineQueryResultsButton;
11
+ }
12
+
13
+ export interface InlineQueryResultsButton {
14
+ text: string;
15
+ webApp?: { url: string };
16
+ startParameter?: string;
17
+ }
18
+
19
+ export interface AnswerCallbackQueryOptions {
20
+ callbackQueryId: string;
21
+ text?: string;
22
+ showAlert?: boolean;
23
+ url?: string;
24
+ cacheTime?: number;
25
+ }
26
+
27
+ /**
28
+ * Telegram Inline API
29
+ */
30
+ export class InlineApi {
31
+ constructor(private readonly client: TelegramClient) {}
32
+
33
+ /**
34
+ * Answer an inline query
35
+ */
36
+ async answerInlineQuery(options: AnswerInlineQueryOptions): Promise<boolean> {
37
+ return this.client.request<boolean>('answerInlineQuery', {
38
+ params: {
39
+ inline_query_id: options.inlineQueryId,
40
+ results: JSON.stringify(options.results),
41
+ cache_time: options.cacheTime,
42
+ is_personal: options.isPersonal,
43
+ next_offset: options.nextOffset,
44
+ button: options.button ? JSON.stringify(options.button) : undefined,
45
+ },
46
+ });
47
+ }
48
+
49
+ /**
50
+ * Answer a callback query
51
+ */
52
+ async answerCallbackQuery(options: AnswerCallbackQueryOptions): Promise<boolean> {
53
+ return this.client.request<boolean>('answerCallbackQuery', {
54
+ params: {
55
+ callback_query_id: options.callbackQueryId,
56
+ text: options.text,
57
+ show_alert: options.showAlert,
58
+ url: options.url,
59
+ cache_time: options.cacheTime,
60
+ },
61
+ });
62
+ }
63
+ }