@pocketping/sdk-node 1.2.0 → 1.4.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,103 @@ 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
+
212
+ ### Reply Behavior
213
+
214
+ - **Telegram:** uses native replies when `replyTo` is set and the Telegram message ID is available.
215
+ - **Discord:** uses native replies via `message_reference` when the Discord message ID is available.
216
+ - **Slack:** renders a quoted block (left bar) in the thread.
217
+
146
218
  ## Architecture Options
147
219
 
148
- ### 1. Embedded Mode (Simple)
220
+ ### 1. Embedded Mode with Built-in Bridges (Simple)
149
221
 
150
- SDK handles everything directly - best for single server deployments:
222
+ SDK handles everything directly including notifications - best for single server deployments:
151
223
 
152
224
  ```typescript
153
- import { PocketPing } from '@pocketping/sdk-node';
225
+ import { PocketPing, TelegramBridge } from '@pocketping/sdk-node';
154
226
 
155
227
  const pp = new PocketPing({
156
228
  welcomeMessage: 'Hello!',
157
229
  });
158
230
 
231
+ pp.addBridge(new TelegramBridge({
232
+ botToken: process.env.TELEGRAM_BOT_TOKEN!,
233
+ chatIds: process.env.TELEGRAM_CHAT_ID!,
234
+ }));
235
+
159
236
  app.use('/pocketping', pp.middleware());
160
237
  pp.attachWebSocket(server);
161
238
  ```
162
239
 
163
- ### 2. Bridge Server Mode (Recommended)
240
+ ### 2. Bridge Server Mode (Production)
164
241
 
165
- SDK connects to a dedicated bridge server for notifications:
242
+ SDK connects to a dedicated bridge server (written in Go) for notifications:
166
243
 
167
244
  ```typescript
168
245
  const pp = new PocketPing({
@@ -171,7 +248,61 @@ const pp = new PocketPing({
171
248
  });
172
249
  ```
173
250
 
174
- The bridge server handles Telegram, Discord, and Slack integrations, keeping your main server lightweight.
251
+ The bridge server handles Telegram, Discord, and Slack integrations via HTTP APIs, keeping your main server lightweight.
252
+
253
+ ## Receiving Operator Messages (WebhookHandler)
254
+
255
+ To receive replies from operators via Telegram, Discord, or Slack, use the `WebhookHandler`:
256
+
257
+ ```typescript
258
+ import { WebhookHandler } from '@pocketping/sdk-node';
259
+
260
+ const webhookHandler = new WebhookHandler({
261
+ telegramBotToken: process.env.TELEGRAM_BOT_TOKEN,
262
+ slackBotToken: process.env.SLACK_BOT_TOKEN,
263
+ discordBotToken: process.env.DISCORD_BOT_TOKEN,
264
+ allowedBotIds: process.env.BRIDGE_TEST_BOT_IDS?.split(',').map((id) => id.trim()).filter(Boolean),
265
+ onOperatorMessage: async (sessionId, content, operatorName, source, attachments) => {
266
+ console.log(`Message from ${operatorName} via ${source}: ${content}`);
267
+
268
+ // Forward to widget
269
+ await pp.sendOperatorMessage(sessionId, content, source, operatorName);
270
+
271
+ // Handle attachments
272
+ for (const att of attachments) {
273
+ console.log(`Attachment: ${att.filename} (${att.size} bytes)`);
274
+ // att.data contains the file bytes
275
+ }
276
+ },
277
+ onOperatorMessageEdit: async (sessionId, bridgeMessageId, content, source) => {
278
+ console.log(`Edited message ${bridgeMessageId} via ${source}: ${content}`);
279
+ },
280
+ onOperatorMessageDelete: async (sessionId, bridgeMessageId, source) => {
281
+ console.log(`Deleted message ${bridgeMessageId} via ${source}`);
282
+ },
283
+ });
284
+
285
+ // Mount webhook routes
286
+ app.post('/webhooks/telegram', async (req, res) => {
287
+ const result = await webhookHandler.handleTelegramWebhook(req.body);
288
+ res.json(result);
289
+ });
290
+
291
+ app.post('/webhooks/slack', async (req, res) => {
292
+ const result = await webhookHandler.handleSlackWebhook(req.body);
293
+ res.json(result);
294
+ });
295
+
296
+ app.post('/webhooks/discord', async (req, res) => {
297
+ const result = await webhookHandler.handleDiscordWebhook(req.body);
298
+ res.json(result);
299
+ });
300
+ ```
301
+
302
+ Configure webhooks on each platform to point to your server:
303
+ - **Telegram**: Use `setWebhook` API
304
+ - **Slack**: Configure Event Subscriptions
305
+ - **Discord**: Set up Interactions Endpoint
175
306
 
176
307
  ## Custom Storage
177
308