Amirio
Amirio

Reputation: 788

how to send message to bale bot by command in linux for authed users?

we need solutions to send a message by Linux command by call bot:

python testbot.py "hello authed users:)"

Is this approach feasible?

Upvotes: 4

Views: 92

Answers (1)

Ehsan
Ehsan

Reputation: 4291

Yes, It's not too hard. First, you need to use sys.argv to get passed argument to testbot.py. like this:

arg = sys.argv[1]

After, you need to create a bot connection and send a message to the client. Here is a full sample:

import sys

import asyncio

from balebot.models.base_models import Peer
from balebot.models.constants.peer_type import PeerType
from balebot.models.messages import *
from balebot.updater import Updater

updater = Updater(token="bot_token",
                  loop=asyncio.get_event_loop())
bot = updater.bot
dispatcher = updater.dispatcher


def success(result, user_data):
    print("success : ", result)
    print(user_data)


def failure(result, user_data):
    print("failure : ", result)
    print(user_data)


arg = sys.argv[1]
text_message = TextMessage(arg)
bot.send_message(text_message, Peer(peer_type=PeerType.user, peer_id="user_id", access_hash="user_access_hash"),
                 success_callback=success, failure_callback=failure)

updater.run(stop_after=3)

Finally run this command in terminal:

python examples/amirio.py "hello authed users:)"

Upvotes: 5

Related Questions