Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python3
Usage: <receiver> <message> [--file=<file>] (-h | --help) --version
-f <file> --file=<file> Sends a file, with message as its caption.
-h --help Show this screen.
--version Show version.
Examples: some_friend "I love you ^_^" --file="~/pics/big_heart.png"
Created by Fereidoon Mehri. I release my contribution to this program to the public domain (CC0).
from docopt import docopt
import os, sys
import asyncio
from telethon import TelegramClient, events
arguments = docopt(__doc__, version='telegram-send 0.1')
async def main():
os.chdir(os.path.dirname(os.path.realpath(sys.argv[0]))) #Changes pwd to real path, useful for using symlinks for the script.
with open('./config') as f:
api_id = f.readline()
api_hash = f.readline()
async with TelegramClient(
api_hash) as client:
# print(arguments)
# if arguments['--file'] is not none:
await client.send_message(arguments['<receiver>'], arguments['<message>'], file=arguments['--file'])
loop = asyncio.get_event_loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment