@contractspec/integration.providers-impls 3.7.7 → 3.8.2
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.
- package/dist/impls/index.d.ts +1 -0
- package/dist/impls/index.js +51 -0
- package/dist/impls/messaging-telegram.d.ts +13 -0
- package/dist/impls/messaging-telegram.js +49 -0
- package/dist/impls/provider-factory.js +50 -0
- package/dist/index.js +51 -0
- package/dist/node/impls/index.js +51 -0
- package/dist/node/impls/messaging-telegram.js +49 -0
- package/dist/node/impls/provider-factory.js +50 -0
- package/dist/node/index.js +51 -0
- package/package.json +18 -6
package/dist/impls/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export * from './jira';
|
|
|
19
19
|
export * from './linear';
|
|
20
20
|
export * from './messaging-github';
|
|
21
21
|
export * from './messaging-slack';
|
|
22
|
+
export * from './messaging-telegram';
|
|
22
23
|
export * from './messaging-whatsapp-meta';
|
|
23
24
|
export * from './messaging-whatsapp-twilio';
|
|
24
25
|
export * from './mistral-conversational';
|
package/dist/impls/index.js
CHANGED
|
@@ -4329,6 +4329,50 @@ class SlackMessagingProvider {
|
|
|
4329
4329
|
}
|
|
4330
4330
|
}
|
|
4331
4331
|
|
|
4332
|
+
// src/impls/messaging-telegram.ts
|
|
4333
|
+
class TelegramMessagingProvider {
|
|
4334
|
+
botToken;
|
|
4335
|
+
defaultChatId;
|
|
4336
|
+
apiBaseUrl;
|
|
4337
|
+
constructor(options) {
|
|
4338
|
+
this.botToken = options.botToken;
|
|
4339
|
+
this.defaultChatId = options.defaultChatId;
|
|
4340
|
+
this.apiBaseUrl = options.apiBaseUrl ?? "https://api.telegram.org";
|
|
4341
|
+
}
|
|
4342
|
+
async sendMessage(input) {
|
|
4343
|
+
const chatId = input.channelId ?? input.recipientId ?? this.defaultChatId ?? undefined;
|
|
4344
|
+
if (!chatId) {
|
|
4345
|
+
throw new Error("Telegram sendMessage requires channelId, recipientId, or defaultChatId.");
|
|
4346
|
+
}
|
|
4347
|
+
const messageThreadId = input.threadId && input.threadId !== chatId ? Number.parseInt(input.threadId, 10) : undefined;
|
|
4348
|
+
const response = await fetch(`${this.apiBaseUrl}/bot${this.botToken}/sendMessage`, {
|
|
4349
|
+
method: "POST",
|
|
4350
|
+
headers: {
|
|
4351
|
+
"content-type": "application/json"
|
|
4352
|
+
},
|
|
4353
|
+
body: JSON.stringify({
|
|
4354
|
+
chat_id: chatId,
|
|
4355
|
+
text: input.text,
|
|
4356
|
+
message_thread_id: Number.isFinite(messageThreadId) ? messageThreadId : undefined
|
|
4357
|
+
})
|
|
4358
|
+
});
|
|
4359
|
+
const body = await response.json();
|
|
4360
|
+
const providerMessageId = body.result?.message_id;
|
|
4361
|
+
if (!response.ok || !body.ok || providerMessageId == null) {
|
|
4362
|
+
throw new Error(`Telegram sendMessage failed: ${body.description ?? `HTTP_${response.status}`}`);
|
|
4363
|
+
}
|
|
4364
|
+
return {
|
|
4365
|
+
id: `telegram:${chatId}:${providerMessageId}`,
|
|
4366
|
+
providerMessageId: String(providerMessageId),
|
|
4367
|
+
status: "sent",
|
|
4368
|
+
sentAt: new Date,
|
|
4369
|
+
metadata: {
|
|
4370
|
+
chatId: String(body.result?.chat?.id ?? chatId)
|
|
4371
|
+
}
|
|
4372
|
+
};
|
|
4373
|
+
}
|
|
4374
|
+
}
|
|
4375
|
+
|
|
4332
4376
|
// src/impls/messaging-whatsapp-meta.ts
|
|
4333
4377
|
class MetaWhatsappMessagingProvider {
|
|
4334
4378
|
accessToken;
|
|
@@ -7071,6 +7115,12 @@ class IntegrationProviderFactory {
|
|
|
7071
7115
|
defaultRepo: config?.defaultRepo,
|
|
7072
7116
|
apiBaseUrl: config?.apiBaseUrl
|
|
7073
7117
|
});
|
|
7118
|
+
case "messaging.telegram":
|
|
7119
|
+
return new TelegramMessagingProvider({
|
|
7120
|
+
botToken: requireSecret(secrets, "botToken", "Telegram bot token is required"),
|
|
7121
|
+
defaultChatId: config?.defaultChatId,
|
|
7122
|
+
apiBaseUrl: config?.apiBaseUrl
|
|
7123
|
+
});
|
|
7074
7124
|
case "messaging.whatsapp.meta":
|
|
7075
7125
|
return new MetaWhatsappMessagingProvider({
|
|
7076
7126
|
accessToken: requireSecret(secrets, "accessToken", "Meta WhatsApp access token is required"),
|
|
@@ -7449,6 +7499,7 @@ export {
|
|
|
7449
7499
|
TwilioWhatsappMessagingProvider,
|
|
7450
7500
|
TwilioSmsProvider,
|
|
7451
7501
|
TldvMeetingRecorderProvider,
|
|
7502
|
+
TelegramMessagingProvider,
|
|
7452
7503
|
SupabaseVectorProvider,
|
|
7453
7504
|
SupabasePostgresProvider,
|
|
7454
7505
|
StripePaymentsProvider,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MessagingProvider, MessagingSendInput, MessagingSendResult } from '../messaging';
|
|
2
|
+
export interface TelegramMessagingProviderOptions {
|
|
3
|
+
botToken: string;
|
|
4
|
+
defaultChatId?: string;
|
|
5
|
+
apiBaseUrl?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class TelegramMessagingProvider implements MessagingProvider {
|
|
8
|
+
private readonly botToken;
|
|
9
|
+
private readonly defaultChatId?;
|
|
10
|
+
private readonly apiBaseUrl;
|
|
11
|
+
constructor(options: TelegramMessagingProviderOptions);
|
|
12
|
+
sendMessage(input: MessagingSendInput): Promise<MessagingSendResult>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __require = import.meta.require;
|
|
3
|
+
|
|
4
|
+
// src/impls/messaging-telegram.ts
|
|
5
|
+
class TelegramMessagingProvider {
|
|
6
|
+
botToken;
|
|
7
|
+
defaultChatId;
|
|
8
|
+
apiBaseUrl;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.botToken = options.botToken;
|
|
11
|
+
this.defaultChatId = options.defaultChatId;
|
|
12
|
+
this.apiBaseUrl = options.apiBaseUrl ?? "https://api.telegram.org";
|
|
13
|
+
}
|
|
14
|
+
async sendMessage(input) {
|
|
15
|
+
const chatId = input.channelId ?? input.recipientId ?? this.defaultChatId ?? undefined;
|
|
16
|
+
if (!chatId) {
|
|
17
|
+
throw new Error("Telegram sendMessage requires channelId, recipientId, or defaultChatId.");
|
|
18
|
+
}
|
|
19
|
+
const messageThreadId = input.threadId && input.threadId !== chatId ? Number.parseInt(input.threadId, 10) : undefined;
|
|
20
|
+
const response = await fetch(`${this.apiBaseUrl}/bot${this.botToken}/sendMessage`, {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: {
|
|
23
|
+
"content-type": "application/json"
|
|
24
|
+
},
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
chat_id: chatId,
|
|
27
|
+
text: input.text,
|
|
28
|
+
message_thread_id: Number.isFinite(messageThreadId) ? messageThreadId : undefined
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
const body = await response.json();
|
|
32
|
+
const providerMessageId = body.result?.message_id;
|
|
33
|
+
if (!response.ok || !body.ok || providerMessageId == null) {
|
|
34
|
+
throw new Error(`Telegram sendMessage failed: ${body.description ?? `HTTP_${response.status}`}`);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
id: `telegram:${chatId}:${providerMessageId}`,
|
|
38
|
+
providerMessageId: String(providerMessageId),
|
|
39
|
+
status: "sent",
|
|
40
|
+
sentAt: new Date,
|
|
41
|
+
metadata: {
|
|
42
|
+
chatId: String(body.result?.chat?.id ?? chatId)
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
TelegramMessagingProvider
|
|
49
|
+
};
|
|
@@ -3203,6 +3203,50 @@ class SlackMessagingProvider {
|
|
|
3203
3203
|
}
|
|
3204
3204
|
}
|
|
3205
3205
|
|
|
3206
|
+
// src/impls/messaging-telegram.ts
|
|
3207
|
+
class TelegramMessagingProvider {
|
|
3208
|
+
botToken;
|
|
3209
|
+
defaultChatId;
|
|
3210
|
+
apiBaseUrl;
|
|
3211
|
+
constructor(options) {
|
|
3212
|
+
this.botToken = options.botToken;
|
|
3213
|
+
this.defaultChatId = options.defaultChatId;
|
|
3214
|
+
this.apiBaseUrl = options.apiBaseUrl ?? "https://api.telegram.org";
|
|
3215
|
+
}
|
|
3216
|
+
async sendMessage(input) {
|
|
3217
|
+
const chatId = input.channelId ?? input.recipientId ?? this.defaultChatId ?? undefined;
|
|
3218
|
+
if (!chatId) {
|
|
3219
|
+
throw new Error("Telegram sendMessage requires channelId, recipientId, or defaultChatId.");
|
|
3220
|
+
}
|
|
3221
|
+
const messageThreadId = input.threadId && input.threadId !== chatId ? Number.parseInt(input.threadId, 10) : undefined;
|
|
3222
|
+
const response = await fetch(`${this.apiBaseUrl}/bot${this.botToken}/sendMessage`, {
|
|
3223
|
+
method: "POST",
|
|
3224
|
+
headers: {
|
|
3225
|
+
"content-type": "application/json"
|
|
3226
|
+
},
|
|
3227
|
+
body: JSON.stringify({
|
|
3228
|
+
chat_id: chatId,
|
|
3229
|
+
text: input.text,
|
|
3230
|
+
message_thread_id: Number.isFinite(messageThreadId) ? messageThreadId : undefined
|
|
3231
|
+
})
|
|
3232
|
+
});
|
|
3233
|
+
const body = await response.json();
|
|
3234
|
+
const providerMessageId = body.result?.message_id;
|
|
3235
|
+
if (!response.ok || !body.ok || providerMessageId == null) {
|
|
3236
|
+
throw new Error(`Telegram sendMessage failed: ${body.description ?? `HTTP_${response.status}`}`);
|
|
3237
|
+
}
|
|
3238
|
+
return {
|
|
3239
|
+
id: `telegram:${chatId}:${providerMessageId}`,
|
|
3240
|
+
providerMessageId: String(providerMessageId),
|
|
3241
|
+
status: "sent",
|
|
3242
|
+
sentAt: new Date,
|
|
3243
|
+
metadata: {
|
|
3244
|
+
chatId: String(body.result?.chat?.id ?? chatId)
|
|
3245
|
+
}
|
|
3246
|
+
};
|
|
3247
|
+
}
|
|
3248
|
+
}
|
|
3249
|
+
|
|
3206
3250
|
// src/impls/messaging-whatsapp-meta.ts
|
|
3207
3251
|
class MetaWhatsappMessagingProvider {
|
|
3208
3252
|
accessToken;
|
|
@@ -5945,6 +5989,12 @@ class IntegrationProviderFactory {
|
|
|
5945
5989
|
defaultRepo: config?.defaultRepo,
|
|
5946
5990
|
apiBaseUrl: config?.apiBaseUrl
|
|
5947
5991
|
});
|
|
5992
|
+
case "messaging.telegram":
|
|
5993
|
+
return new TelegramMessagingProvider({
|
|
5994
|
+
botToken: requireSecret(secrets, "botToken", "Telegram bot token is required"),
|
|
5995
|
+
defaultChatId: config?.defaultChatId,
|
|
5996
|
+
apiBaseUrl: config?.apiBaseUrl
|
|
5997
|
+
});
|
|
5948
5998
|
case "messaging.whatsapp.meta":
|
|
5949
5999
|
return new MetaWhatsappMessagingProvider({
|
|
5950
6000
|
accessToken: requireSecret(secrets, "accessToken", "Meta WhatsApp access token is required"),
|
package/dist/index.js
CHANGED
|
@@ -4347,6 +4347,50 @@ class SlackMessagingProvider {
|
|
|
4347
4347
|
}
|
|
4348
4348
|
}
|
|
4349
4349
|
|
|
4350
|
+
// src/impls/messaging-telegram.ts
|
|
4351
|
+
class TelegramMessagingProvider {
|
|
4352
|
+
botToken;
|
|
4353
|
+
defaultChatId;
|
|
4354
|
+
apiBaseUrl;
|
|
4355
|
+
constructor(options) {
|
|
4356
|
+
this.botToken = options.botToken;
|
|
4357
|
+
this.defaultChatId = options.defaultChatId;
|
|
4358
|
+
this.apiBaseUrl = options.apiBaseUrl ?? "https://api.telegram.org";
|
|
4359
|
+
}
|
|
4360
|
+
async sendMessage(input) {
|
|
4361
|
+
const chatId = input.channelId ?? input.recipientId ?? this.defaultChatId ?? undefined;
|
|
4362
|
+
if (!chatId) {
|
|
4363
|
+
throw new Error("Telegram sendMessage requires channelId, recipientId, or defaultChatId.");
|
|
4364
|
+
}
|
|
4365
|
+
const messageThreadId = input.threadId && input.threadId !== chatId ? Number.parseInt(input.threadId, 10) : undefined;
|
|
4366
|
+
const response = await fetch(`${this.apiBaseUrl}/bot${this.botToken}/sendMessage`, {
|
|
4367
|
+
method: "POST",
|
|
4368
|
+
headers: {
|
|
4369
|
+
"content-type": "application/json"
|
|
4370
|
+
},
|
|
4371
|
+
body: JSON.stringify({
|
|
4372
|
+
chat_id: chatId,
|
|
4373
|
+
text: input.text,
|
|
4374
|
+
message_thread_id: Number.isFinite(messageThreadId) ? messageThreadId : undefined
|
|
4375
|
+
})
|
|
4376
|
+
});
|
|
4377
|
+
const body = await response.json();
|
|
4378
|
+
const providerMessageId = body.result?.message_id;
|
|
4379
|
+
if (!response.ok || !body.ok || providerMessageId == null) {
|
|
4380
|
+
throw new Error(`Telegram sendMessage failed: ${body.description ?? `HTTP_${response.status}`}`);
|
|
4381
|
+
}
|
|
4382
|
+
return {
|
|
4383
|
+
id: `telegram:${chatId}:${providerMessageId}`,
|
|
4384
|
+
providerMessageId: String(providerMessageId),
|
|
4385
|
+
status: "sent",
|
|
4386
|
+
sentAt: new Date,
|
|
4387
|
+
metadata: {
|
|
4388
|
+
chatId: String(body.result?.chat?.id ?? chatId)
|
|
4389
|
+
}
|
|
4390
|
+
};
|
|
4391
|
+
}
|
|
4392
|
+
}
|
|
4393
|
+
|
|
4350
4394
|
// src/impls/messaging-whatsapp-meta.ts
|
|
4351
4395
|
class MetaWhatsappMessagingProvider {
|
|
4352
4396
|
accessToken;
|
|
@@ -7089,6 +7133,12 @@ class IntegrationProviderFactory {
|
|
|
7089
7133
|
defaultRepo: config?.defaultRepo,
|
|
7090
7134
|
apiBaseUrl: config?.apiBaseUrl
|
|
7091
7135
|
});
|
|
7136
|
+
case "messaging.telegram":
|
|
7137
|
+
return new TelegramMessagingProvider({
|
|
7138
|
+
botToken: requireSecret(secrets, "botToken", "Telegram bot token is required"),
|
|
7139
|
+
defaultChatId: config?.defaultChatId,
|
|
7140
|
+
apiBaseUrl: config?.apiBaseUrl
|
|
7141
|
+
});
|
|
7092
7142
|
case "messaging.whatsapp.meta":
|
|
7093
7143
|
return new MetaWhatsappMessagingProvider({
|
|
7094
7144
|
accessToken: requireSecret(secrets, "accessToken", "Meta WhatsApp access token is required"),
|
|
@@ -7496,6 +7546,7 @@ export {
|
|
|
7496
7546
|
TwilioWhatsappMessagingProvider,
|
|
7497
7547
|
TwilioSmsProvider,
|
|
7498
7548
|
TldvMeetingRecorderProvider,
|
|
7549
|
+
TelegramMessagingProvider,
|
|
7499
7550
|
SupabaseVectorProvider,
|
|
7500
7551
|
SupabasePostgresProvider,
|
|
7501
7552
|
StripePaymentsProvider,
|
package/dist/node/impls/index.js
CHANGED
|
@@ -4329,6 +4329,50 @@ class SlackMessagingProvider {
|
|
|
4329
4329
|
}
|
|
4330
4330
|
}
|
|
4331
4331
|
|
|
4332
|
+
// src/impls/messaging-telegram.ts
|
|
4333
|
+
class TelegramMessagingProvider {
|
|
4334
|
+
botToken;
|
|
4335
|
+
defaultChatId;
|
|
4336
|
+
apiBaseUrl;
|
|
4337
|
+
constructor(options) {
|
|
4338
|
+
this.botToken = options.botToken;
|
|
4339
|
+
this.defaultChatId = options.defaultChatId;
|
|
4340
|
+
this.apiBaseUrl = options.apiBaseUrl ?? "https://api.telegram.org";
|
|
4341
|
+
}
|
|
4342
|
+
async sendMessage(input) {
|
|
4343
|
+
const chatId = input.channelId ?? input.recipientId ?? this.defaultChatId ?? undefined;
|
|
4344
|
+
if (!chatId) {
|
|
4345
|
+
throw new Error("Telegram sendMessage requires channelId, recipientId, or defaultChatId.");
|
|
4346
|
+
}
|
|
4347
|
+
const messageThreadId = input.threadId && input.threadId !== chatId ? Number.parseInt(input.threadId, 10) : undefined;
|
|
4348
|
+
const response = await fetch(`${this.apiBaseUrl}/bot${this.botToken}/sendMessage`, {
|
|
4349
|
+
method: "POST",
|
|
4350
|
+
headers: {
|
|
4351
|
+
"content-type": "application/json"
|
|
4352
|
+
},
|
|
4353
|
+
body: JSON.stringify({
|
|
4354
|
+
chat_id: chatId,
|
|
4355
|
+
text: input.text,
|
|
4356
|
+
message_thread_id: Number.isFinite(messageThreadId) ? messageThreadId : undefined
|
|
4357
|
+
})
|
|
4358
|
+
});
|
|
4359
|
+
const body = await response.json();
|
|
4360
|
+
const providerMessageId = body.result?.message_id;
|
|
4361
|
+
if (!response.ok || !body.ok || providerMessageId == null) {
|
|
4362
|
+
throw new Error(`Telegram sendMessage failed: ${body.description ?? `HTTP_${response.status}`}`);
|
|
4363
|
+
}
|
|
4364
|
+
return {
|
|
4365
|
+
id: `telegram:${chatId}:${providerMessageId}`,
|
|
4366
|
+
providerMessageId: String(providerMessageId),
|
|
4367
|
+
status: "sent",
|
|
4368
|
+
sentAt: new Date,
|
|
4369
|
+
metadata: {
|
|
4370
|
+
chatId: String(body.result?.chat?.id ?? chatId)
|
|
4371
|
+
}
|
|
4372
|
+
};
|
|
4373
|
+
}
|
|
4374
|
+
}
|
|
4375
|
+
|
|
4332
4376
|
// src/impls/messaging-whatsapp-meta.ts
|
|
4333
4377
|
class MetaWhatsappMessagingProvider {
|
|
4334
4378
|
accessToken;
|
|
@@ -7071,6 +7115,12 @@ class IntegrationProviderFactory {
|
|
|
7071
7115
|
defaultRepo: config?.defaultRepo,
|
|
7072
7116
|
apiBaseUrl: config?.apiBaseUrl
|
|
7073
7117
|
});
|
|
7118
|
+
case "messaging.telegram":
|
|
7119
|
+
return new TelegramMessagingProvider({
|
|
7120
|
+
botToken: requireSecret(secrets, "botToken", "Telegram bot token is required"),
|
|
7121
|
+
defaultChatId: config?.defaultChatId,
|
|
7122
|
+
apiBaseUrl: config?.apiBaseUrl
|
|
7123
|
+
});
|
|
7074
7124
|
case "messaging.whatsapp.meta":
|
|
7075
7125
|
return new MetaWhatsappMessagingProvider({
|
|
7076
7126
|
accessToken: requireSecret(secrets, "accessToken", "Meta WhatsApp access token is required"),
|
|
@@ -7449,6 +7499,7 @@ export {
|
|
|
7449
7499
|
TwilioWhatsappMessagingProvider,
|
|
7450
7500
|
TwilioSmsProvider,
|
|
7451
7501
|
TldvMeetingRecorderProvider,
|
|
7502
|
+
TelegramMessagingProvider,
|
|
7452
7503
|
SupabaseVectorProvider,
|
|
7453
7504
|
SupabasePostgresProvider,
|
|
7454
7505
|
StripePaymentsProvider,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
// src/impls/messaging-telegram.ts
|
|
5
|
+
class TelegramMessagingProvider {
|
|
6
|
+
botToken;
|
|
7
|
+
defaultChatId;
|
|
8
|
+
apiBaseUrl;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.botToken = options.botToken;
|
|
11
|
+
this.defaultChatId = options.defaultChatId;
|
|
12
|
+
this.apiBaseUrl = options.apiBaseUrl ?? "https://api.telegram.org";
|
|
13
|
+
}
|
|
14
|
+
async sendMessage(input) {
|
|
15
|
+
const chatId = input.channelId ?? input.recipientId ?? this.defaultChatId ?? undefined;
|
|
16
|
+
if (!chatId) {
|
|
17
|
+
throw new Error("Telegram sendMessage requires channelId, recipientId, or defaultChatId.");
|
|
18
|
+
}
|
|
19
|
+
const messageThreadId = input.threadId && input.threadId !== chatId ? Number.parseInt(input.threadId, 10) : undefined;
|
|
20
|
+
const response = await fetch(`${this.apiBaseUrl}/bot${this.botToken}/sendMessage`, {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: {
|
|
23
|
+
"content-type": "application/json"
|
|
24
|
+
},
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
chat_id: chatId,
|
|
27
|
+
text: input.text,
|
|
28
|
+
message_thread_id: Number.isFinite(messageThreadId) ? messageThreadId : undefined
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
const body = await response.json();
|
|
32
|
+
const providerMessageId = body.result?.message_id;
|
|
33
|
+
if (!response.ok || !body.ok || providerMessageId == null) {
|
|
34
|
+
throw new Error(`Telegram sendMessage failed: ${body.description ?? `HTTP_${response.status}`}`);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
id: `telegram:${chatId}:${providerMessageId}`,
|
|
38
|
+
providerMessageId: String(providerMessageId),
|
|
39
|
+
status: "sent",
|
|
40
|
+
sentAt: new Date,
|
|
41
|
+
metadata: {
|
|
42
|
+
chatId: String(body.result?.chat?.id ?? chatId)
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
TelegramMessagingProvider
|
|
49
|
+
};
|
|
@@ -3203,6 +3203,50 @@ class SlackMessagingProvider {
|
|
|
3203
3203
|
}
|
|
3204
3204
|
}
|
|
3205
3205
|
|
|
3206
|
+
// src/impls/messaging-telegram.ts
|
|
3207
|
+
class TelegramMessagingProvider {
|
|
3208
|
+
botToken;
|
|
3209
|
+
defaultChatId;
|
|
3210
|
+
apiBaseUrl;
|
|
3211
|
+
constructor(options) {
|
|
3212
|
+
this.botToken = options.botToken;
|
|
3213
|
+
this.defaultChatId = options.defaultChatId;
|
|
3214
|
+
this.apiBaseUrl = options.apiBaseUrl ?? "https://api.telegram.org";
|
|
3215
|
+
}
|
|
3216
|
+
async sendMessage(input) {
|
|
3217
|
+
const chatId = input.channelId ?? input.recipientId ?? this.defaultChatId ?? undefined;
|
|
3218
|
+
if (!chatId) {
|
|
3219
|
+
throw new Error("Telegram sendMessage requires channelId, recipientId, or defaultChatId.");
|
|
3220
|
+
}
|
|
3221
|
+
const messageThreadId = input.threadId && input.threadId !== chatId ? Number.parseInt(input.threadId, 10) : undefined;
|
|
3222
|
+
const response = await fetch(`${this.apiBaseUrl}/bot${this.botToken}/sendMessage`, {
|
|
3223
|
+
method: "POST",
|
|
3224
|
+
headers: {
|
|
3225
|
+
"content-type": "application/json"
|
|
3226
|
+
},
|
|
3227
|
+
body: JSON.stringify({
|
|
3228
|
+
chat_id: chatId,
|
|
3229
|
+
text: input.text,
|
|
3230
|
+
message_thread_id: Number.isFinite(messageThreadId) ? messageThreadId : undefined
|
|
3231
|
+
})
|
|
3232
|
+
});
|
|
3233
|
+
const body = await response.json();
|
|
3234
|
+
const providerMessageId = body.result?.message_id;
|
|
3235
|
+
if (!response.ok || !body.ok || providerMessageId == null) {
|
|
3236
|
+
throw new Error(`Telegram sendMessage failed: ${body.description ?? `HTTP_${response.status}`}`);
|
|
3237
|
+
}
|
|
3238
|
+
return {
|
|
3239
|
+
id: `telegram:${chatId}:${providerMessageId}`,
|
|
3240
|
+
providerMessageId: String(providerMessageId),
|
|
3241
|
+
status: "sent",
|
|
3242
|
+
sentAt: new Date,
|
|
3243
|
+
metadata: {
|
|
3244
|
+
chatId: String(body.result?.chat?.id ?? chatId)
|
|
3245
|
+
}
|
|
3246
|
+
};
|
|
3247
|
+
}
|
|
3248
|
+
}
|
|
3249
|
+
|
|
3206
3250
|
// src/impls/messaging-whatsapp-meta.ts
|
|
3207
3251
|
class MetaWhatsappMessagingProvider {
|
|
3208
3252
|
accessToken;
|
|
@@ -5945,6 +5989,12 @@ class IntegrationProviderFactory {
|
|
|
5945
5989
|
defaultRepo: config?.defaultRepo,
|
|
5946
5990
|
apiBaseUrl: config?.apiBaseUrl
|
|
5947
5991
|
});
|
|
5992
|
+
case "messaging.telegram":
|
|
5993
|
+
return new TelegramMessagingProvider({
|
|
5994
|
+
botToken: requireSecret(secrets, "botToken", "Telegram bot token is required"),
|
|
5995
|
+
defaultChatId: config?.defaultChatId,
|
|
5996
|
+
apiBaseUrl: config?.apiBaseUrl
|
|
5997
|
+
});
|
|
5948
5998
|
case "messaging.whatsapp.meta":
|
|
5949
5999
|
return new MetaWhatsappMessagingProvider({
|
|
5950
6000
|
accessToken: requireSecret(secrets, "accessToken", "Meta WhatsApp access token is required"),
|
package/dist/node/index.js
CHANGED
|
@@ -4347,6 +4347,50 @@ class SlackMessagingProvider {
|
|
|
4347
4347
|
}
|
|
4348
4348
|
}
|
|
4349
4349
|
|
|
4350
|
+
// src/impls/messaging-telegram.ts
|
|
4351
|
+
class TelegramMessagingProvider {
|
|
4352
|
+
botToken;
|
|
4353
|
+
defaultChatId;
|
|
4354
|
+
apiBaseUrl;
|
|
4355
|
+
constructor(options) {
|
|
4356
|
+
this.botToken = options.botToken;
|
|
4357
|
+
this.defaultChatId = options.defaultChatId;
|
|
4358
|
+
this.apiBaseUrl = options.apiBaseUrl ?? "https://api.telegram.org";
|
|
4359
|
+
}
|
|
4360
|
+
async sendMessage(input) {
|
|
4361
|
+
const chatId = input.channelId ?? input.recipientId ?? this.defaultChatId ?? undefined;
|
|
4362
|
+
if (!chatId) {
|
|
4363
|
+
throw new Error("Telegram sendMessage requires channelId, recipientId, or defaultChatId.");
|
|
4364
|
+
}
|
|
4365
|
+
const messageThreadId = input.threadId && input.threadId !== chatId ? Number.parseInt(input.threadId, 10) : undefined;
|
|
4366
|
+
const response = await fetch(`${this.apiBaseUrl}/bot${this.botToken}/sendMessage`, {
|
|
4367
|
+
method: "POST",
|
|
4368
|
+
headers: {
|
|
4369
|
+
"content-type": "application/json"
|
|
4370
|
+
},
|
|
4371
|
+
body: JSON.stringify({
|
|
4372
|
+
chat_id: chatId,
|
|
4373
|
+
text: input.text,
|
|
4374
|
+
message_thread_id: Number.isFinite(messageThreadId) ? messageThreadId : undefined
|
|
4375
|
+
})
|
|
4376
|
+
});
|
|
4377
|
+
const body = await response.json();
|
|
4378
|
+
const providerMessageId = body.result?.message_id;
|
|
4379
|
+
if (!response.ok || !body.ok || providerMessageId == null) {
|
|
4380
|
+
throw new Error(`Telegram sendMessage failed: ${body.description ?? `HTTP_${response.status}`}`);
|
|
4381
|
+
}
|
|
4382
|
+
return {
|
|
4383
|
+
id: `telegram:${chatId}:${providerMessageId}`,
|
|
4384
|
+
providerMessageId: String(providerMessageId),
|
|
4385
|
+
status: "sent",
|
|
4386
|
+
sentAt: new Date,
|
|
4387
|
+
metadata: {
|
|
4388
|
+
chatId: String(body.result?.chat?.id ?? chatId)
|
|
4389
|
+
}
|
|
4390
|
+
};
|
|
4391
|
+
}
|
|
4392
|
+
}
|
|
4393
|
+
|
|
4350
4394
|
// src/impls/messaging-whatsapp-meta.ts
|
|
4351
4395
|
class MetaWhatsappMessagingProvider {
|
|
4352
4396
|
accessToken;
|
|
@@ -7089,6 +7133,12 @@ class IntegrationProviderFactory {
|
|
|
7089
7133
|
defaultRepo: config?.defaultRepo,
|
|
7090
7134
|
apiBaseUrl: config?.apiBaseUrl
|
|
7091
7135
|
});
|
|
7136
|
+
case "messaging.telegram":
|
|
7137
|
+
return new TelegramMessagingProvider({
|
|
7138
|
+
botToken: requireSecret(secrets, "botToken", "Telegram bot token is required"),
|
|
7139
|
+
defaultChatId: config?.defaultChatId,
|
|
7140
|
+
apiBaseUrl: config?.apiBaseUrl
|
|
7141
|
+
});
|
|
7092
7142
|
case "messaging.whatsapp.meta":
|
|
7093
7143
|
return new MetaWhatsappMessagingProvider({
|
|
7094
7144
|
accessToken: requireSecret(secrets, "accessToken", "Meta WhatsApp access token is required"),
|
|
@@ -7496,6 +7546,7 @@ export {
|
|
|
7496
7546
|
TwilioWhatsappMessagingProvider,
|
|
7497
7547
|
TwilioSmsProvider,
|
|
7498
7548
|
TldvMeetingRecorderProvider,
|
|
7549
|
+
TelegramMessagingProvider,
|
|
7499
7550
|
SupabaseVectorProvider,
|
|
7500
7551
|
SupabasePostgresProvider,
|
|
7501
7552
|
StripePaymentsProvider,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractspec/integration.providers-impls",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.2",
|
|
4
4
|
"description": "Integration provider implementations for email, payments, storage, and more",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contractspec",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"typecheck": "tsc --noEmit"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@contractspec/lib.contracts-spec": "4.
|
|
36
|
-
"@contractspec/lib.contracts-integrations": "3.
|
|
37
|
-
"@contractspec/integration.runtime": "3.
|
|
35
|
+
"@contractspec/lib.contracts-spec": "4.1.2",
|
|
36
|
+
"@contractspec/lib.contracts-integrations": "3.8.2",
|
|
37
|
+
"@contractspec/integration.runtime": "3.8.2",
|
|
38
38
|
"@elevenlabs/elevenlabs-js": "^2.38.1",
|
|
39
39
|
"@fal-ai/client": "^1.9.4",
|
|
40
40
|
"@google-cloud/storage": "^7.19.0",
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/bun": "1.3.11",
|
|
59
|
-
"@contractspec/tool.typescript": "3.7.
|
|
59
|
+
"@contractspec/tool.typescript": "3.7.8",
|
|
60
60
|
"typescript": "^5.9.3",
|
|
61
|
-
"@contractspec/tool.bun": "3.7.
|
|
61
|
+
"@contractspec/tool.bun": "3.7.8"
|
|
62
62
|
},
|
|
63
63
|
"exports": {
|
|
64
64
|
".": {
|
|
@@ -319,6 +319,12 @@
|
|
|
319
319
|
"node": "./dist/node/impls/messaging-slack.js",
|
|
320
320
|
"default": "./dist/impls/messaging-slack.js"
|
|
321
321
|
},
|
|
322
|
+
"./impls/messaging-telegram": {
|
|
323
|
+
"types": "./dist/impls/messaging-telegram.d.ts",
|
|
324
|
+
"bun": "./dist/impls/messaging-telegram.js",
|
|
325
|
+
"node": "./dist/node/impls/messaging-telegram.js",
|
|
326
|
+
"default": "./dist/impls/messaging-telegram.js"
|
|
327
|
+
},
|
|
322
328
|
"./impls/messaging-whatsapp-meta": {
|
|
323
329
|
"types": "./dist/impls/messaging-whatsapp-meta.d.ts",
|
|
324
330
|
"bun": "./dist/impls/messaging-whatsapp-meta.js",
|
|
@@ -779,6 +785,12 @@
|
|
|
779
785
|
"node": "./dist/node/impls/messaging-slack.js",
|
|
780
786
|
"default": "./dist/impls/messaging-slack.js"
|
|
781
787
|
},
|
|
788
|
+
"./impls/messaging-telegram": {
|
|
789
|
+
"types": "./dist/impls/messaging-telegram.d.ts",
|
|
790
|
+
"bun": "./dist/impls/messaging-telegram.js",
|
|
791
|
+
"node": "./dist/node/impls/messaging-telegram.js",
|
|
792
|
+
"default": "./dist/impls/messaging-telegram.js"
|
|
793
|
+
},
|
|
782
794
|
"./impls/messaging-whatsapp-meta": {
|
|
783
795
|
"types": "./dist/impls/messaging-whatsapp-meta.d.ts",
|
|
784
796
|
"bun": "./dist/impls/messaging-whatsapp-meta.js",
|