Code Monkey home page Code Monkey logo

Comments (4)

MajMcCloud avatar MajMcCloud commented on June 18, 2024

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.

amirreza58 avatar amirreza58 commented on June 18, 2024

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.

amirreza58 avatar amirreza58 commented on June 18, 2024

ok i removed Telegram.Bot from .nuget and restored , problem solved.

from telegrambotframework.

MajMcCloud avatar MajMcCloud commented on June 18, 2024

Ok, so we can close this one ?

from telegrambotframework.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.