|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: Quickstart Visual Studio |
| 4 | +parent: Quickstart overview |
| 5 | +nav_order: 2 |
| 6 | +--- |
| 7 | + |
| 8 | +# Quickstart Guide (Visual Studio) |
| 9 | + |
| 10 | +Hey 👋, |
| 11 | +thanks for using [RxTelegram.Bot](https://github.com/RxTelegram/RxTelegram.Bot). This quickstart guide will give you an easy 3 Steps Solution how you can get started with RxTelegram.Bot using Visual Studio. Quickstart guides are also Available for the Terminal or Rider. |
| 12 | + |
| 13 | +## 1. Bot Father |
| 14 | + |
| 15 | +Before we can get started you need to create a Telegram Bot by visiting [@BotFather](https://t.me/BotFather) with any Telegram client and create a new bot. He will give you an access token which you need to authorize your bot at every request, but do not worry we will handle this for you. |
| 16 | + |
| 17 | +## 2. Hello World - by clicking |
| 18 | + |
| 19 | +This Tutotial will not explain how to get Visual Studio installed, but you need a working Visual Studio installation __with the ".NET Core cross-platform development" workload installed__ so go and set it up. It is quite simple just ask any search engine and you will find many tutorial or click [here](https://docs.microsoft.com/en-us/visualstudio/install/install-visual-studio?view=vs-2019) follow the offical tutorial by Microsoft. |
| 20 | + |
| 21 | +So since you have a running Visual Studio installation, lets begin. |
| 22 | + |
| 23 | +### 2.1 Create a Project |
| 24 | + |
| 25 | +First of all you have to create a new "Console Project" as shown in the video below. |
| 26 | + |
| 27 | + |
| 28 | +### 2.2 Install RxTelegram.Bot |
| 29 | + |
| 30 | +Now you have to install the [RxTelegram.Bot](https://github.com/RxTelegram/RxTelegram.Bot) Nuget package as shown in the video below. |
| 31 | + |
| 32 | + |
| 33 | +### 2.3 Paste the code |
| 34 | + |
| 35 | +Open the ```Programm.cs``` file and paste the following content. |
| 36 | + |
| 37 | +> **Replace ACCESS_TOKEN_HERE with the access token Botfaher gave you.** |
| 38 | +
|
| 39 | +```csharp |
| 40 | +using System; |
| 41 | +using RxTelegram.Bot; |
| 42 | + |
| 43 | +namespace Awesome { |
| 44 | + class Program { |
| 45 | + public static void Main () { |
| 46 | + var botClient = new TelegramBot ("ACCESS_TOKEN_HERE"); |
| 47 | + var me = botClient.GetMe().Result; |
| 48 | + Console.WriteLine ( |
| 49 | + $"Hello, World! I am user {me.Id} and my name is {me.FirstName}." |
| 50 | + ); |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +## 3. Run your programm |
| 57 | + |
| 58 | +The last step is quid simple. Just click on the "Awesome" button and your awesome Project will start. |
| 59 | + |
| 60 | + |
| 61 | +## Troubleshooting |
| 62 | + |
| 63 | +### Invalid Bot Token |
| 64 | + |
| 65 | +```text |
| 66 | +Unhandled exception. RxTelegram.Bot.Exceptions.InvalidTokenException: The given bot token is not valid. See "https://core.telegram.org/bots/api#authorizing-your-bot" for further information. Token was: ACCESS_TOKEN_HERE |
| 67 | + at RxTelegram.Bot.BotInfo.ValidateToken(String token) |
| 68 | + at RxTelegram.Bot.BotInfo..ctor(String token) |
| 69 | + at RxTelegram.Bot.TelegramBot..ctor(String token) |
| 70 | + at Awesome.Program.Main() in C:\Users\nikwe\Downloads\asf\Program.cs:line 7 |
| 71 | +``` |
| 72 | + |
| 73 | +If you get an Exception like this it is most likely that you did not replaced the access token in the code sample or you copied the wrong one. |
0 commit comments