Comments (4)
Hey!
you should be able to run it as a background task. I would say.
Take a look at "HostedService"
Should be easy to implement.
Warm Regards
Florian Zevedei
from telegrambotframework.
Hi
I tried using "HostedService" but it cause Errors
public class TelegramWorker : IHostedService
{
private readonly IConfiguration _configuration;
public TelegramWorker(IConfiguration configuration)
{
_configuration = configuration;
}
public async Task StartAsync(CancellationToken cancellationToken)
{
var botConfig = _configuration.GetSection("TelegramBotConfiguration").Get<BotConfiguration>();
var bot = BotBaseBuilder
.Create()
.WithAPIKey(botConfig.BotToken)
.DefaultMessageLoop()
.WithStartForm<StartForm>()
.WithHostAndPort("127.0.0.1", 10809)
.CustomCommands(a =>
{
a.Start("Starts the bot");
})
.NoSerialization()
.UseEnglish()
.Build();
// Upload bot commands to BotFather
//await bot.UploadBotCommands();
// Start your Bot
bot.Start();
}
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
first with "await bot.UploadBotCommands()" :
An error occurred while starting the application.
JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
Newtonsoft.Json.JsonTextReader.ParseValue()
RequestException: Required properties not found in response 1<!DOCTYPE html>
<html class="">
<head>
<meta charset="utf-8">
<title>Bots: An introduction for developers</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="description" content="Bots are small applications that run entirely within the Telegram app. Users interact with bots through flexible interfaces…">
<meta property="og:title" content="Bots: An introduction for developers">
<meta property="og:image" content="75f7c457f2561cbf84">
<meta property="og:description" content="Bots are small applications that run entirely within the Telegram app. Users interact with bots through flexible interfaces…">
<link rel="icon" type="image/svg+xml" href="/img/website_icon.svg?4">
<link rel="apple-touch-icon" sizes="180x180" href="/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/img/favicon-16x16.png">
<link rel="alternate icon" href="/img/favicon.ico" type="image/x-icon" />
<link href="/css/bootstrap.min.css?3" rel="stylesheet">
<link href="/css/telegram.css?233" rel="stylesheet" media="screen">
<style>
</style>
</head>
<body class="preload">
<div class="dev_page_wrap">
<div class="dev_page_head navbar navbar-static-top navbar-tg">
....
without it my app stopped with :
GET https://localhost:44314/ net::ERR_CONTENT_DECODING_FAILED 200
from telegrambotframework.
ok i removed Telegram.Bot from .nuget and restored , problem solved.
from telegrambotframework.
Ok, so we can close this one ?
from telegrambotframework.
Related Issues (18)
- Method not found: 'Void Telegram.Bot.TelegramBotClient..ctor HOT 3
- Add method to save session states directly without stopping the Bot HOT 2
- Why won't raise init and open events of forms with index less than 2? HOT 3
- How to use the repo to chat with some chat bot? HOT 12
- Exception on Calling InvokeMessageLoop on DefaultMessageLoop when there is no "userevent" HOT 4
- Keyboard Markup always is hided when navigate to next form on phone but not on desktop HOT 5
- Keyboard Markup HOT 5
- How can i use NavigationController HOT 9
- Exception when use Calendar/Month picker HOT 1
- What different between Init and Opened event? HOT 1
- How can i serialize state of controls? HOT 6
- How session serializer works? HOT 6
- Proactively Send a Form to User HOT 11
- Improve navigation use DI and IServiceProvider HOT 1
- Sending text null check HOT 5
- ButtonGrid does ConfirmAction even when the button is not inside the datasource
- Incorrect overwriting of an error message during resolving dependencies HOT 1
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 telegrambotframework.