@bytesbrains/pi-telegram-bridge 1.0.1 → 1.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytesbrains/pi-telegram-bridge",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Telegram bot bridge for pi agents — send messages, ask questions, and listen for human replies via Telegram.",
5
5
  "keywords": [
6
6
  "pi-package",
package/src/helpers.ts CHANGED
@@ -67,7 +67,11 @@ export async function pollReply(
67
67
  // Drain pending updates to start fresh
68
68
  let lastId = 0;
69
69
  try {
70
- const drain = await fetch(`${BASE_URL}${token}/getUpdates?timeout=0`);
70
+ const drain = await fetch(`${BASE_URL}${token}/getUpdates`, {
71
+ method: "POST",
72
+ headers: { "Content-Type": "application/json" },
73
+ body: JSON.stringify({ timeout: 0 }),
74
+ });
71
75
  if (drain.ok) {
72
76
  const d = (await drain.json()) as {
73
77
  ok: boolean;
@@ -83,7 +87,12 @@ export async function pollReply(
83
87
 
84
88
  while (Date.now() < deadline) {
85
89
  const res = await fetch(
86
- `${BASE_URL}${token}/getUpdates?offset=${lastId + 1}&timeout=5`,
90
+ `${BASE_URL}${token}/getUpdates`,
91
+ {
92
+ method: "POST",
93
+ headers: { "Content-Type": "application/json" },
94
+ body: JSON.stringify({ offset: lastId + 1, timeout: 5 }),
95
+ },
87
96
  );
88
97
  if (!res.ok) {
89
98
  await new Promise((r) => setTimeout(r, 3000));
@@ -154,7 +163,10 @@ export async function seedLastUpdateId(
154
163
  if (lastUpdateId !== 0) return lastUpdateId;
155
164
  const token = getToken();
156
165
  try {
157
- const res = await fetch(`${BASE_URL}${token}/getUpdates?timeout=0`, {
166
+ const res = await fetch(`${BASE_URL}${token}/getUpdates`, {
167
+ method: "POST",
168
+ headers: { "Content-Type": "application/json" },
169
+ body: JSON.stringify({ timeout: 0 }),
158
170
  signal,
159
171
  });
160
172
  if (res.ok) {
@@ -184,8 +196,13 @@ export async function pollUpdates(
184
196
  while (!signal.aborted) {
185
197
  try {
186
198
  const res = await fetch(
187
- `${BASE_URL}${token}/getUpdates?offset=${lastUpdateId + 1}&timeout=10`,
188
- { signal },
199
+ `${BASE_URL}${token}/getUpdates`,
200
+ {
201
+ method: "POST",
202
+ headers: { "Content-Type": "application/json" },
203
+ body: JSON.stringify({ offset: lastUpdateId + 1, timeout: 10 }),
204
+ signal,
205
+ },
189
206
  );
190
207
  if (!res.ok) {
191
208
  await new Promise((r) => setTimeout(r, 3000));
package/src/index.ts CHANGED
@@ -102,7 +102,12 @@ export default function telegramBridge(pi: ExtensionAPI) {
102
102
  if (!botId) botId = await getBotId();
103
103
 
104
104
  const res = await fetch(
105
- `https://api.telegram.org/bot${token}/getUpdates?offset=${lastUpdateId + 1}&timeout=5`,
105
+ `https://api.telegram.org/bot${token}/getUpdates`,
106
+ {
107
+ method: "POST",
108
+ headers: { "Content-Type": "application/json" },
109
+ body: JSON.stringify({ offset: lastUpdateId + 1, timeout: 5 }),
110
+ },
106
111
  );
107
112
  if (!res.ok)
108
113
  return {