Merge pull request #35 from uriyyo/main
Add ability to run telegram-mcp using uvx
This commit is contained in:
commit
83c2c73a3b
5 changed files with 100 additions and 83 deletions
1
__init__.py
Normal file
1
__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
# Telegram MCP Package
|
||||
14
main.py
14
main.py
|
|
@ -3129,10 +3129,7 @@ async def create_poll(
|
|||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
nest_asyncio.apply()
|
||||
|
||||
async def main() -> None:
|
||||
async def _main() -> None:
|
||||
try:
|
||||
# Start the Telethon client non-interactively
|
||||
print("Starting Telegram client...")
|
||||
|
|
@ -3150,4 +3147,11 @@ if __name__ == "__main__":
|
|||
)
|
||||
sys.exit(1)
|
||||
|
||||
asyncio.run(main())
|
||||
|
||||
def main() -> None:
|
||||
nest_asyncio.apply()
|
||||
asyncio.run(_main())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
[build-system]
|
||||
requires = ["setuptools>=42", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
package-mode = false
|
||||
|
||||
[project]
|
||||
name = "telegram-mcp"
|
||||
|
|
@ -26,7 +25,7 @@ requires-python = ">=3.10"
|
|||
dependencies = [
|
||||
"dotenv>=0.9.9",
|
||||
"httpx>=0.28.1",
|
||||
"mcp[cli]>=1.4.1",
|
||||
"mcp[cli]>=1.8.0",
|
||||
"nest-asyncio>=1.6.0",
|
||||
"python-dotenv>=1.1.0",
|
||||
"python-json-logger>=3.3.0",
|
||||
|
|
@ -37,6 +36,13 @@ dependencies = [
|
|||
"Homepage" = "https://github.com/chigwell/telegram-mcp"
|
||||
"Bug Tracker" = "https://github.com/chigwell/telegram-mcp/issues"
|
||||
|
||||
[tool.setuptools]
|
||||
py-modules = ["main", "session_string_generator"]
|
||||
|
||||
[project.scripts]
|
||||
telegram-mcp = "main:main"
|
||||
telegram-mcp-generate-session = "session_string_generator:main"
|
||||
|
||||
[tool.black]
|
||||
line-length = 99
|
||||
target-version = ['py311']
|
||||
|
|
|
|||
|
|
@ -28,32 +28,34 @@ import sys
|
|||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
API_ID = os.getenv("TELEGRAM_API_ID")
|
||||
API_HASH = os.getenv("TELEGRAM_API_HASH")
|
||||
|
||||
if not API_ID or not API_HASH:
|
||||
def main() -> None:
|
||||
API_ID = os.getenv("TELEGRAM_API_ID")
|
||||
API_HASH = os.getenv("TELEGRAM_API_HASH")
|
||||
|
||||
if not API_ID or not API_HASH:
|
||||
print("Error: TELEGRAM_API_ID and TELEGRAM_API_HASH must be set in .env file")
|
||||
print("Create an .env file with your credentials from https://my.telegram.org/apps")
|
||||
sys.exit(1)
|
||||
|
||||
# Convert API_ID to integer
|
||||
try:
|
||||
# Convert API_ID to integer
|
||||
try:
|
||||
API_ID = int(API_ID)
|
||||
except ValueError:
|
||||
except ValueError:
|
||||
print("Error: TELEGRAM_API_ID must be an integer")
|
||||
sys.exit(1)
|
||||
|
||||
print("\n----- Telegram Session String Generator -----\n")
|
||||
print("This script will generate a session string for your Telegram account.")
|
||||
print(
|
||||
print("\n----- Telegram Session String Generator -----\n")
|
||||
print("This script will generate a session string for your Telegram account.")
|
||||
print(
|
||||
"You will be asked to enter your phone number and the verification code sent to your Telegram app."
|
||||
)
|
||||
print("The generated session string can be added to your .env file.")
|
||||
print(
|
||||
)
|
||||
print("The generated session string can be added to your .env file.")
|
||||
print(
|
||||
"\nYour credentials will NOT be stored on any server and are only used for local authentication.\n"
|
||||
)
|
||||
)
|
||||
|
||||
try:
|
||||
try:
|
||||
# Connect to Telegram and generate the session string
|
||||
with TelegramClient(StringSession(), API_ID, API_HASH) as client:
|
||||
# The client.session.save() function from StringSession returns the session string
|
||||
|
|
@ -96,7 +98,11 @@ try:
|
|||
print(f"\nError updating .env file: {e}")
|
||||
print("Please manually add the session string to your .env file.")
|
||||
|
||||
except Exception as e:
|
||||
except Exception as e:
|
||||
print(f"\nError: {e}")
|
||||
print("Failed to generate session string. Please try again.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
2
uv.lock
2
uv.lock
|
|
@ -995,7 +995,7 @@ dev = [
|
|||
requires-dist = [
|
||||
{ name = "dotenv", specifier = ">=0.9.9" },
|
||||
{ name = "httpx", specifier = ">=0.28.1" },
|
||||
{ name = "mcp", extras = ["cli"], specifier = ">=1.4.1" },
|
||||
{ name = "mcp", extras = ["cli"], specifier = ">=1.8.0" },
|
||||
{ name = "nest-asyncio", specifier = ">=1.6.0" },
|
||||
{ name = "python-dotenv", specifier = ">=1.1.0" },
|
||||
{ name = "python-json-logger", specifier = ">=3.3.0" },
|
||||
|
|
|
|||
Loading…
Reference in a new issue