orchestrix-yuri 2.3.1 → 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.
@@ -83,16 +83,11 @@ class TelegramAdapter {
83
83
  });
84
84
 
85
85
  // Force-disconnect any stale polling connection before starting.
86
- // deleteWebhook clears webhooks but does NOT terminate existing
87
- // long-polling getUpdates connections. A short getUpdates call
88
- // with timeout=0 "steals" the connection, terminating the old one.
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.
89
89
  log.telegram('Connecting...');
90
- try {
91
- await this.bot.api.deleteWebhook({ drop_pending_updates: true });
92
- await this.bot.api.raw.getUpdates({ offset: -1, limit: 1, timeout: 0 });
93
- } catch {
94
- // ignore — best effort cleanup
95
- }
90
+ await forceDisconnectPolling(this.token);
96
91
 
97
92
  // Start polling
98
93
  await this.bot.start({
@@ -144,4 +139,38 @@ function splitMessage(text, maxLength) {
144
139
  return chunks;
145
140
  }
146
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
+
147
176
  module.exports = { TelegramAdapter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orchestrix-yuri",
3
- "version": "2.3.1",
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": {