@pocketping/sdk-node 1.1.0 → 1.3.0

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/README.md CHANGED
@@ -143,26 +143,97 @@ const clientIp = pp.getClientIp(request.headers);
143
143
  // Checks: CF-Connecting-IP, X-Real-IP, X-Forwarded-For
144
144
  ```
145
145
 
146
+ ## Built-in Bridges
147
+
148
+ The SDK includes built-in bridges for Telegram, Discord, and Slack. No external libraries required - all communication uses HTTP APIs directly.
149
+
150
+ ### Telegram Bridge
151
+
152
+ ```typescript
153
+ import { PocketPing, TelegramBridge } from '@pocketping/sdk-node';
154
+
155
+ const pp = new PocketPing({
156
+ welcomeMessage: 'Hello!',
157
+ });
158
+
159
+ pp.addBridge(new TelegramBridge({
160
+ botToken: process.env.TELEGRAM_BOT_TOKEN!,
161
+ chatIds: process.env.TELEGRAM_CHAT_ID!,
162
+ showUrl: true, // Show page URL in notifications
163
+ }));
164
+ ```
165
+
166
+ ### Discord Bridge
167
+
168
+ ```typescript
169
+ import { PocketPing, DiscordBridge } from '@pocketping/sdk-node';
170
+
171
+ // Webhook mode (simple, send-only)
172
+ pp.addBridge(DiscordBridge.withWebhook({
173
+ webhookUrl: process.env.DISCORD_WEBHOOK_URL!,
174
+ }));
175
+
176
+ // Or Bot mode (bidirectional)
177
+ pp.addBridge(DiscordBridge.withBot({
178
+ botToken: process.env.DISCORD_BOT_TOKEN!,
179
+ channelId: process.env.DISCORD_CHANNEL_ID!,
180
+ }));
181
+ ```
182
+
183
+ ### Slack Bridge
184
+
185
+ ```typescript
186
+ import { PocketPing, SlackBridge } from '@pocketping/sdk-node';
187
+
188
+ // Webhook mode (simple, send-only)
189
+ pp.addBridge(SlackBridge.withWebhook({
190
+ webhookUrl: process.env.SLACK_WEBHOOK_URL!,
191
+ }));
192
+
193
+ // Or Bot mode (bidirectional)
194
+ pp.addBridge(SlackBridge.withBot({
195
+ botToken: process.env.SLACK_BOT_TOKEN!,
196
+ channelId: process.env.SLACK_CHANNEL_ID!,
197
+ }));
198
+ ```
199
+
200
+ ### Multiple Bridges
201
+
202
+ You can add multiple bridges to receive notifications on all platforms simultaneously:
203
+
204
+ ```typescript
205
+ const pp = new PocketPing({ welcomeMessage: 'Hello!' });
206
+
207
+ pp.addBridge(new TelegramBridge({ ... }));
208
+ pp.addBridge(DiscordBridge.withBot({ ... }));
209
+ pp.addBridge(SlackBridge.withWebhook({ ... }));
210
+ ```
211
+
146
212
  ## Architecture Options
147
213
 
148
- ### 1. Embedded Mode (Simple)
214
+ ### 1. Embedded Mode with Built-in Bridges (Simple)
149
215
 
150
- SDK handles everything directly - best for single server deployments:
216
+ SDK handles everything directly including notifications - best for single server deployments:
151
217
 
152
218
  ```typescript
153
- import { PocketPing } from '@pocketping/sdk-node';
219
+ import { PocketPing, TelegramBridge } from '@pocketping/sdk-node';
154
220
 
155
221
  const pp = new PocketPing({
156
222
  welcomeMessage: 'Hello!',
157
223
  });
158
224
 
225
+ pp.addBridge(new TelegramBridge({
226
+ botToken: process.env.TELEGRAM_BOT_TOKEN!,
227
+ chatIds: process.env.TELEGRAM_CHAT_ID!,
228
+ }));
229
+
159
230
  app.use('/pocketping', pp.middleware());
160
231
  pp.attachWebSocket(server);
161
232
  ```
162
233
 
163
- ### 2. Bridge Server Mode (Recommended)
234
+ ### 2. Bridge Server Mode (Production)
164
235
 
165
- SDK connects to a dedicated bridge server for notifications:
236
+ SDK connects to a dedicated bridge server (written in Go) for notifications:
166
237
 
167
238
  ```typescript
168
239
  const pp = new PocketPing({
@@ -171,7 +242,54 @@ const pp = new PocketPing({
171
242
  });
172
243
  ```
173
244
 
174
- The bridge server handles Telegram, Discord, and Slack integrations, keeping your main server lightweight.
245
+ The bridge server handles Telegram, Discord, and Slack integrations via HTTP APIs, keeping your main server lightweight.
246
+
247
+ ## Receiving Operator Messages (WebhookHandler)
248
+
249
+ To receive replies from operators via Telegram, Discord, or Slack, use the `WebhookHandler`:
250
+
251
+ ```typescript
252
+ import { WebhookHandler } from '@pocketping/sdk-node';
253
+
254
+ const webhookHandler = new WebhookHandler({
255
+ telegramBotToken: process.env.TELEGRAM_BOT_TOKEN,
256
+ slackBotToken: process.env.SLACK_BOT_TOKEN,
257
+ discordBotToken: process.env.DISCORD_BOT_TOKEN,
258
+ onOperatorMessage: async (sessionId, content, operatorName, source, attachments) => {
259
+ console.log(`Message from ${operatorName} via ${source}: ${content}`);
260
+
261
+ // Forward to widget
262
+ await pp.sendOperatorMessage(sessionId, content, source, operatorName);
263
+
264
+ // Handle attachments
265
+ for (const att of attachments) {
266
+ console.log(`Attachment: ${att.filename} (${att.size} bytes)`);
267
+ // att.data contains the file bytes
268
+ }
269
+ },
270
+ });
271
+
272
+ // Mount webhook routes
273
+ app.post('/webhooks/telegram', async (req, res) => {
274
+ const result = await webhookHandler.handleTelegramWebhook(req.body);
275
+ res.json(result);
276
+ });
277
+
278
+ app.post('/webhooks/slack', async (req, res) => {
279
+ const result = await webhookHandler.handleSlackWebhook(req.body);
280
+ res.json(result);
281
+ });
282
+
283
+ app.post('/webhooks/discord', async (req, res) => {
284
+ const result = await webhookHandler.handleDiscordWebhook(req.body);
285
+ res.json(result);
286
+ });
287
+ ```
288
+
289
+ Configure webhooks on each platform to point to your server:
290
+ - **Telegram**: Use `setWebhook` API
291
+ - **Slack**: Configure Event Subscriptions
292
+ - **Discord**: Set up Interactions Endpoint
175
293
 
176
294
  ## Custom Storage
177
295