logbot icon indicating copy to clipboard operation
logbot copied to clipboard

Host & Port configuration

Open drpaprika opened this issue 5 years ago • 4 comments

Hi, I'm having trouble setting up the bot using Python. Following the instructions in ReadMe : pip install logbot-telegram

Then,

from logbot import Client
c = Client(token=mytoken, host=host, port=port)
c.send("Hello World")

mytoken has been provided by BotFather. Which host and port should I use to receive the message in Telegram ? Or am I missing a step ?

Thanks !

drpaprika avatar Jun 01 '20 12:06 drpaprika

Hi,

You have to do one thing first, which is running the actual bot, it's explained further down in the Readme (https://github.com/apiad/logbot#setting-up-your-own) but basically it is just:

  • export TOKEN=<yourtoken>
  • python -m logbot

That will run the bot that will connect to Telegram and it will listen at localhost:6778 for the Client, which is what you run with the code you're showing. I used to have running on a public URL but it is down now.

Hope this helps, let me know if you need any clarification. Cheers!

apiad avatar Jun 01 '20 13:06 apiad

Thanks for the very quick answer !

Is it possible to store the token in a file of my project and not use the export option ? Should I always start the bot (via python -m logbot) before running my script that contains the c.send("Hello World") part or is it a one-time thing ?

I'm saying all this trying to understand how it works, since my script is currently running on my PC but will eventually be running remotely from a Rasperry Pi.

drpaprika avatar Jun 01 '20 13:06 drpaprika

Sure, don't be afraid to ask. I'm just happy someone is using this.

Usually, bots are run once and stay up. However, you can turn it off if you want, it all depends on your computational constraints. In this case, since the only user will be you, and you know exactly when you want the bot to be online, I think it's the same. However, if you plan to have the bot listening on some public IP so that different people can log to it, leaving it up will be the way to go. It's very lightweight in any case so there is no need, I think, to turn it off. Whatever is simpler for you.

Regarding the environment variables, I, unfortunately, didn't add a CLI option, but what you can do is in the bash line do everything, like:

TOKEN=<yourtoken> PORT=<yourport> python -m logbot

This is a bash thing, not anything specifically related to logbot. If it makes it any easier for you I can simply add a --token ... option to the CLI, but it's not going to save you any extra typing from the previous form. I haven't thought of config files but I could add that as well. Let me know if this is something you would like to have.

Cheers.

apiad avatar Jun 01 '20 13:06 apiad

Thanks for the reply, I'll be looking into it !

drpaprika avatar Jun 01 '20 16:06 drpaprika