Skip to content

burakguldiken/software-training-telegram-bot

Repository files navigation

Telegram Software Training Bot

  • you can take questions and practice programming languages

  • you can consolidate your knowledge or learn new information

  • you can make your free time efficient

General

you can list commands after pressing /

an error message will return to you when a message is sent, except for commands

C#, html,css,javascript, python, etc. question categories for programming languages will be added

Install

you can use this link to install Telegram bot : Telegram User Bot Kurulumu Nasıl Yapılır? - Teknoloji Haberleri (teknobilimadami.com)

after the bot is created, the Telegram key given to you must be saved,and then it will be needed in the application.

Usage

  • List available commands with "/" key

  • Select the command related to the field you want among them

  • As a result, you will be sent a relevant question.

  • After creating the bot, save the key given for you and do not share it with anyone, you can use it as follows.

public TelegramClient()
        {
            telegramBotKey = "SET YOUR KEY";
        }
public ITelegramBotClient CreateInstance()
        {
            if(botClient == null)
            {
               lock(lockObject)
                {
                    botClient = new TelegramBotClient(telegramBotKey);
                } 
            }

            return botClient;
        }
  • The service used to send questions can be defined as follows.Chat id value, question title, question types, poll type (in this example it can be quiz, questionnaire, etc.) should be sent as parameters.
public async Task ExecuteCommand(Message message,int category = 1)
        {
            var question = questionRepository.GetRandomQuestion(category);

            if(question == null)
            {
                await telegramBotClient.SendTextMessageAsync(message.Chat.Id, Messages.categoryNotFound);

                return;
            }

            await telegramBotClient.SendPollAsync(
                chatId: message.Chat.Id,
                question: question.title,
                options: new[]
                {
                    question.optionA,
                    question.optionB,
                    question.optionC,
                    question.optionD
                },
                type:PollType.Quiz,
                isAnonymous:false,
                correctOptionId: question.answer
            );
        }

Photos

image1.jpg image2.jpg