خرید بک لینک
using NetTelegramBotApi;
using NetTelegramBotApi.Requests;
using NetTelegramBotApi.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using TelegramBotSharp;
//using TelegramBotSharp.Types;

namespace testBot
{
class Program
{
public static TelegramBot bot;
public static NetTelegramBotApi.Types.ReplyKeyboardMarkup rkm = new ReplyKeyboardMarkup();

static void Main(string[] args)
{
bot = new TelegramBot("423986824:AAHPcaXbxLo6eOdpsc-2CC7rsPEmrfZb1d4");
rkm.Keyboard =
new KeyboardButton[][]
{
new KeyboardButton[]
{
new KeyboardButton("U0001F602 راهنما") ,
new KeyboardButton("U0001F4AC درباره ما")

},

new KeyboardButton[]
{
new KeyboardButton("U0001F4D5 آموزش")
},

new KeyboardButton[]
{
new KeyboardButton(" U0001F393 اساتید"),
new KeyboardButton("U0001F3E6 سمینار "),
new KeyboardButton("U0001F3B8 زمانبندی")
},
new KeyboardButton[]
{
new KeyboardButton("shared your contact")
{
RequestContact = true

}
}

};
try
{

Task.Run(() => RunBot());
Console.ReadLine();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message );
Console.WriteLine(ex.StackTrace);
}
}

public static async Task RunBot()
{

try
{
var me = await bot.MakeRequestAsync(new GetMe());
Console.WriteLine("username is {0}", me.Username);

long offset = 0;
int count = 0;
while (true)
{
var updates = await bot.MakeRequestAsync(new GetUpdates() { Offset = offset });

foreach (var update in updates)
{

offset = update.UpdateId + 1;
var text = update.Message.Text;
Console.WriteLine(text);
if (text == null)
{

continue;
}
else if (text == "/start")
{
var req = new SendMessage(update.Message.Chat.Id, "Hello") { ReplyMarkup = rkm };

await bot.MakeRequestAsync(req);
continue;
}
else if (text == "U0001F4AC درباره ما")
{
var req = new SendMessage(update.Message.Chat.Id, "ربات تلگرام") { ReplyMarkup = rkm };
await bot.MakeRequestAsync(req);
continue;
}
else
{
var req = new SendMessage(update.Message.Chat.Id, "مقدار غیر مجاز وارد شده است") { ReplyMarkup = rkm };
await bot.MakeRequestAsync(req);
continue;
}

}
}
}
catch (TimeoutException time)
{
Console.WriteLine(1);
Console.WriteLine(time.Message );
}
catch (MessageLockLostException locks)
{
Console.WriteLine(2);
Console.WriteLine(locks.Message);
}
catch (RedisCoectionException redis)
{
Console.WriteLine("Start the redis server service!");
}
catch (MessagingCommunicationException communication)
{
Console.WriteLine(3);
Console.WriteLine(communication.Message);
}
catch (Exception ex)
{
Console.WriteLine(4);
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);

}
}
}
}

برچسب: نویسنده: محمد رضا جوادیان تاريخ: جمعه 16 تير 1396 ساعت: 20:05

صفحه بندی