reo7sp / tgbot-cpp

C++ library for Telegram bot API

Home Page:http://reo7sp.github.io/tgbot-cpp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to run the bot?

miannoodle01 opened this issue · comments

Hello! I just wrote my code and i compiled it with no errors but I don't know how to run it, on basic run like ./main it throws errors, on normal run and execution this error also occurs on samples which admin posted with API part of code in sample folder the error is as following:
terminate called after throwing an instance of 'std::logic_error' what(): basic_string: construction from null is not valid zsh: IOT instruction ./main
I'm using debian 10 buster.

Hi! Could you provide a minimal code that allows me to reproduce this behavior? I can compile and run all the provided examples normally with ./main

Fixed the issue by putting out the getenv() function, but there is an issue that the admins may fix it; Admins may correct the sample folder of the tgbot for the future guys, may they not face this problem. For example on the line 13th of the echobot sample, it's written like this:
string token(getenv("TOKEN"));
If you faced issue, you may correct the code as below:
string token("TOKEN"); or string token = "TOKEN";
Then the code will work fine!

The getenv() function is actually there to read the token from the environment variable. This prevents the code from being uploaded with the token by mistake and thus exposing it. Granted, it should be written down somewhere that you have to store the token in an environment variable

Okay, so let me ask: How can you run the bot with getenv() function included?

You can add the variable TOKEN as an environment variable. There are plenty of tutorials online on this topic