reo7sp / tgbot-cpp

C++ library for Telegram bot API
http://reo7sp.github.io/tgbot-cpp
MIT License
995 stars 238 forks source link

How to run the bot? #252

Closed miannoodle01 closed 1 year ago

miannoodle01 commented 1 year ago

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.

llnulldisk commented 1 year ago

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

miannoodle01 commented 1 year ago

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!

llnulldisk commented 1 year ago

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

miannoodle01 commented 1 year ago

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

llnulldisk commented 1 year ago

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