.Net Core Console Uygulması İle Telegram Botu Geliştirmek
Merhabalar,bu yazı içerisinde sizlerle telegram bot nasıl oluşturulur ve bu bot ile kullanıcılara nasıl mesaj gönderilir gibi konular üzerinde duracağız.
İlk olarak yapmamız gereken telegram uygulamasına girip,ardından mavi tikli olan kanala giriyoruz.
Şimdi botumuzu oluşturup ona isim verme işlemini gerçekleştireceğiz.Öncelikle “/newbot” komutu ile yeni bir bot oluşturacağımızı belirtiyoruz.Bu komutu gönderdiğimizde bizden bot için bir isim girmemizi isteyecektir.Daha sonra bizden bir username istiyor ve sonunun “bot” ile bitmesi gerektiğini belirtiyor burayada bir isim verdiğimizde işlemler tamamlanıyor ve bize bir token tahsis ediliyor.Bu token’ı bir yere not almanızı tavsiye ederim.Daha sonra uygulama içerisinde ihtiyacımız olacak.
Şimdi bot içerisinde komutlar oluşturalım.Botu kullanan kullanıcılar bu komutları uygulamamıza göndersin ve bizde gönderilen komuta uygun bir cevap dönelim.
Burada öncelikle yeni bir komut set edeceğimizi belirtiyoruz.Daha sonra bize hangi bot için bu işlemi yapmak istediğimizi soruyor botumuzu seçiyoruz.Son olarak “komutAdı-açıklama” olacak şekilde komutu oluşturuyoruz.
Botumuzu oluşturduk ve içerisine bir tanede komut tanımladık şimdi telegram üzerinden gelen mesajları yakalayıp cevap verebileceğimiz kodlarımıza geçelim.
Burada size botu oluşturduğunuz zaman verilen key bilgisini set etmeniz gerekmektedir.Channel’a mesaj gönderirken bu keyden faydalanılıyor.
ITelegramBotClient tipinde bir objemiz var ve StartReceiving() metodu ile telegram üzerinden gönderilen mesajlar yakalanıyor her mesaj geldiğinde “OnMessage” class’ı içerisindeki BotOnMessage methodumuz çağrılmakta.
Telegram üzerinde bir channel’a mesaj göndermek isterken yukarıda ki “SendTextMessageAsync” metodunu kullanabiliriz.Bizden mesajın gönderileceği ChatId değeri ve gönderilecek mesaj içeriği istenmekte.İstenmesi durumunda html tipinde mesajlardan gönderilebilmektedir.(ChatId değeri bize gönderilen mesajlardaki Message nesnesi içerisinde yer almaktadır.)
Telegramda text mesajından hariç olarak resim,video,anket,test gibi seçeneklerde mevcut.Yukarıda veritabanından ilgili kategoriye ait bir soru çekilmekte ve kullanıcıya test sorusu olarak gönderilmekte.Options soruya ait şıklar anlamına gelmektedir.CorrectionOptionId ise hangi şıkkın doğru şık olduğu anlamına gelmektedir.Gönderilen mesajın tipide “PollType.Quiz” ile belirtilmiştir.
Gönderilen örnek bir test uygulaması yukarıdaki gibidir.
Burada yazımın sonuna geliyorum,umarım beğenmişinizdir ve yararlı olmuştur.
Kaynak kodlara : https://lnkd.in/dU8xCif adresinden ulaşabilirsiniz.
Uygulamayı kullanmak için : https://lnkd.in/eJASym3
Ten articles before and after
Como criar um Bot no Telegram com NodeJS – Telegram Group
data-rh=”true”>Airdrop 20 WYD ($50) – ALVIN LAGONERO – Medium – Telegram Group
Telegram Bot in JAVA| by Naveen Kumar M N – Telegram Group
Improved node setup and monitoring for the validator of the Agoric testnet – Telegram Group
Cricket Score Alert Telegram Bot using EspnCricinfo – Telegram Group
Creating a Telegram Bot: Full Beginner’s Guide 2021 – Telegram Group
Sending a message from Python to a Telegram chat: the simplest way – Telegram Group
Create a telegram bot – Telegram Group
Bot Telegram Untuk Membantu Sekolah/Kuliah Kamu – Telegram Group
Пишем telegram бота для мониторинга сайта на Golang – Telegram Group