@bytesbrains/pi-telegram-bridge 1.0.1 → 1.1.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/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));