-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathdirect_message.py
More file actions
33 lines (23 loc) · 1.03 KB
/
Copy pathdirect_message.py
File metadata and controls
33 lines (23 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from __future__ import annotations
import argparse
import asyncio
from _common import env, make_client, parse_ids
async def send_direct(text: str, user_ids: list[int], thread_ids: list[int]):
if bool(user_ids) == bool(thread_ids):
raise SystemExit("Pass exactly one of --user-ids or --thread-ids.")
cl = await make_client()
return await cl.direct_send(text, user_ids=user_ids, thread_ids=thread_ids)
async def main() -> None:
parser = argparse.ArgumentParser(description="Send a Direct text message.")
parser.add_argument("--text", default=env("IG_DIRECT_TEXT", "Hello from aiograpi"))
parser.add_argument("--user-ids", default=env("IG_DIRECT_USER_IDS"))
parser.add_argument("--thread-ids", default=env("IG_DIRECT_THREAD_IDS"))
args = parser.parse_args()
message = await send_direct(
args.text,
user_ids=parse_ids(args.user_ids),
thread_ids=parse_ids(args.thread_ids),
)
print(f"Sent direct message {message.id}")
if __name__ == "__main__":
asyncio.run(main())