orchestrix-yuri 2.3.0 → 2.3.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.
@@ -82,13 +82,12 @@ class TelegramAdapter {
82
82
  log.warn(`Bot error: ${msg}`);
83
83
  });
84
84
 
85
- // Clear any stale webhook/polling before starting
85
+ // Force-disconnect any stale polling connection before starting.
86
+ // deleteWebhook only clears webhooks, NOT existing long-polling connections.
87
+ // A direct getUpdates call with timeout=0 "steals" the polling slot,
88
+ // terminating any other instance's connection.
86
89
  log.telegram('Connecting...');
87
- try {
88
- await this.bot.api.deleteWebhook({ drop_pending_updates: true });
89
- } catch {
90
- // ignore — not critical
91
- }
90
+ await forceDisconnectPolling(this.token);
92
91
 
93
92
  // Start polling
94
93
  await this.bot.start({
@@ -140,4 +139,38 @@ function splitMessage(text, maxLength) {
140
139
  return chunks;
141
140
  }
142
141
 
142
+ /**
143
+ * Force-disconnect any stale polling session via direct Telegram API calls.
144
+ * Uses native https to avoid grammy API quirks.
145
+ */
146
+ function forceDisconnectPolling(token) {
147
+ const https = require('https');
148
+
149
+ const call = (method, body) => new Promise((resolve) => {
150
+ const data = JSON.stringify(body);
151
+ const req = https.request({
152
+ hostname: 'api.telegram.org',
153
+ path: `/bot${token}/${method}`,
154
+ method: 'POST',
155
+ headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(data) },
156
+ timeout: 10000,
157
+ }, (res) => {
158
+ let buf = '';
159
+ res.on('data', (d) => { buf += d; });
160
+ res.on('end', () => resolve(buf));
161
+ });
162
+ req.on('error', () => resolve(null));
163
+ req.on('timeout', () => { req.destroy(); resolve(null); });
164
+ req.write(data);
165
+ req.end();
166
+ });
167
+
168
+ return (async () => {
169
+ await call('deleteWebhook', { drop_pending_updates: true });
170
+ await call('getUpdates', { offset: -1, limit: 1, timeout: 0 });
171
+ // Brief pause to let Telegram release the polling slot
172
+ await new Promise((r) => setTimeout(r, 1000));
173
+ })();
174
+ }
175
+
143
176
  module.exports = { TelegramAdapter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orchestrix-yuri",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "description": "Yuri — Meta-Orchestrator for Orchestrix. Drive your entire project lifecycle with natural language.",
5
5
  "main": "lib/installer.js",
6
6
  "bin": {