Giter Club home page Giter Club logo

Comments (2)

wuyu8512 avatar wuyu8512 commented on July 20, 2024 1

It's good and solved my issue, thanks!!

from telegram.bots.

AmanAgnihotri avatar AmanAgnihotri commented on July 20, 2024

Hello! Thank you for considering Telegram.Bots for your bot project.

In this library, the ideal way of initializing the BotClient is through the dependency injection mechanism. The AddBotClient extension method returns an IHttpClientBuilder which you can then use to setup your proxy, I imagine. I say "I imagine" because I have never set this up myself and so do not fully know whether this will work but I kept the option open nonetheless and here is what I think you can do to get your web proxy working as well:

using System;
using Microsoft.Extensions.DependencyInjection;
using Telegram.Bots;

IServiceProvider provider = new ServiceCollection()
  .AddBotClient("<bot-token>")
  .ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler
  {
    Proxy = new WebProxy(Host: "<your-host>", Port: 1234),
    UseProxy = true
  })
  .Services
  .BuildServiceProvider();

IBotClient bot = provider.GetRequiredService<IBotClient>();

You can further add more HttpClientHandler by calling AddHttpMessageHandler accordingly.

Do let me know if this resolves your issue and I can setup a decent example in the README about using the web proxy then. You can also tell me what you wrote so I can use that as inspiration for the example that can be in the README for future users who also need a web proxy.

from telegram.bots.

Related Issues (6)

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.