Comments (5)
Thanks @HeySreelal for always being the first person to help in the community. I'm working on an update for a while which will include an updated version of the example file but I've not been able to finish it still.
@abduraimovdev please consult the official faq for the webhook configuration https://core.telegram.org/bots/faq#i-39m-having-problems-with-webhooks
from teledart.
Glad to know that. I didn't know that Telegram had a webhook, I imagine it must be very useful in a payment system, which we still don't have in Brazil.
tks
paulo
from teledart.
Hey, I've checked the example file, and I think that's a bit outdated.
Here's an example that I just tested and found to be working fine:
import 'dart:io';
import 'package:teledart/teledart.dart';
import 'package:teledart/telegram.dart';
void main() async {
final token = Platform.environment["BOT_TOKEN"]!;
final telegram = Telegram(token);
final username = (await telegram.getMe()).username!;
final server = await HttpServer.bind(InternetAddress.anyIPv4, 8081);
final webhook = Webhook(
telegram,
"https://yourwebhook-url.com",
server,
);
final bot = TeleDart(
token,
Event(username),
fetcher: webhook,
);
bot.onCommand("start").listen((message) {
message.reply("Hello!");
});
bot.start();
}
If you have a self-signed certificate you can pass the File object to the certificate
parameter - it's optional. Check the setWebhook documentation for more info. Anyway, the above code is working just fine.
Let me know if you have any further concerns.
from teledart.
In my Bots the code I use is the one below.
What is this webhook? When is it used?
void main() async {
late TeleDart teledart;
const token = mytoken;
final username = (await Telegram(token).getMe()).username;
teledart = TeleDart(token, Event(username!));
print('$username ready to work.');
teledart.start();
teledart.onMessage(entityType: 'bot_command').listen((message) async {
checkmessage(message); // there answer everything
});
}
from teledart.
Hi @paulobreim, Telegram supports two ways in which you can listen updates. First one is the LongPolling
which is used by default if you don't pass a fetcher. So from your code, I can say that your bots are using the LongPolling
way to fetch updates.
-
LongPolling
is basically repeatedly calling the getUpdates method and checking if there are updates left to handle. -
Meanwhile,
Webhook
is basically a server endpoint that you leave opened - let's say something like an API endpoint. Whenever there's an update to your bot Telegram Bot API server automatically sends aPOST
request containing the JSON serializedUpdate
object in the body. You can read more about it on setWebhook documentation.
Some side notes are, generally speaking (from my understanding) webhooks are preferred for a bot with large user base. Because, an update is immediately sent to your endpoint right after it is occurred also as they are concurrently processed.
Hope this helps :)
from teledart.
Related Issues (20)
- support for web app bot HOT 3
- Phone messages are not streamed to onMessage stream HOT 3
- Email messages are not streamed to onMessage stream HOT 1
- Url messages are not streamed to onMessage stream HOT 1
- I have problem with message.reply(welcomeMsg) on iOS when app in background and run as profile or release mode. Plz help to check and improve on this! HOT 5
- Update TeleDart to http ^1.0.0
- is it still working ? HOT 6
- Teledart Client HOT 1
- Send message to a topic
- Garbage collection? Memory increase HOT 1
- HttpClientException should be exported. HOT 1
- Editing the inlineKeyboard after an Inline request HOT 1
- OS error semaphore timeout HOT 1
- Forcing optional param to exist HOT 1
- onCallbackQuery not called HOT 2
- LongPollingException: HttpClientException: 409 Conflict HOT 2
- I'm having issue with teledart.onMessage(entityType: '*').listen((message) is not executing when running as Release and the app is in Background state for iOS HOT 1
- How to launch app in telegram because the provided example doesn't do so. Even it doesn't require the hosted website url anywhere. How i can fix this ? HOT 2
- Upgrade Bot API up to 7.5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from teledart.