scripts/dm.py¶
Purpose¶
Send a single one-off Teams message to an explicit chat as the Agent User, without starting an MCP session — for scripted notifications or ad hoc replies from the command line.
Requirements¶
- Python 3.12+ with
entrabotinstalled. - Agent User three-hop credentials configured (same as
catch_up.py). - The target chat must already exist — created via
create_chat, discovered by the running MCP server, or otherwise already known. This command does not create chats and there is no default chat; you must always pass--chatexplicitly. - Works on macOS, Linux, and Windows.
Usage¶
python scripts/dm.py "Your message here" --chat 19:abcdefgh...@unq.gbl.spaces
python scripts/dm.py "Your message here" --chat myalias
Options¶
message(positional, required) — the text to send.--chat(required) — a Graphchat_id, or a key defined in theCHAT_ALIASESdict at the top of the script (empty by default; edit the script to add your own, e.g."alice": "19:xxxx@unq.gbl.spaces"). If the value given isn't a key inCHAT_ALIASES, it is used verbatim as the chat_id.
Effects¶
- Resolves
--chatagainstCHAT_ALIASES, falling back to the literal value when there's no match. - Acquires an Agent User token via
acquire_agent_user_token. - Calls
entrabot.tools.teams.send(chat_id=..., message=..., token=...), which POSTs an HTML-formatted chat message to Graph (content_typedefaults to"html"). - Prints the sent message's Graph
idto stdout, or the literal stringokif the response has noid. - This is a real, visible Graph side effect: the message is delivered to every member of the target chat immediately.
Exit behavior¶
No explicit exit codes are set in source. Success exits 0 via
asyncio.run(main()). --chat is required=True in argparse, so
omitting it triggers argparse's own usage error and exit code 2 before
main()'s body runs. Any other failure — an invalid chat_id, missing
or expired Agent User credentials, a Graph error from send() — surfaces
as an uncaught exception and Python's default non-zero exit; the script
does not catch these itself.
Common failures¶
- Argparse usage error (exit 2) —
--chatwas omitted; it's required on every invocation. - Uncaught
AgentIDNotAvailable— Agent User credentials aren't configured; runsetup.shfirst. - Uncaught Graph error (e.g. invalid
chat_id) — verify the chat_id withcatch_up.pyorshow_agent_status.py, or create the chat first viacreate_chat.
Related commands¶
catch_up.py— see what's arrived in a chat before replying.read_email.py— the mail equivalent of a one-off check.- Guides: Teams and Chat Workflows
- Architecture: Messaging and Delivery
- Operations scripts index