Files
Linux_post_install/bin/pos-entertainment-send
T
Your Name 873ae84b49 refactor: rename telegram tool to pos-communication-telegram-sender; drop --send legacy alias
The --send flag duplicated the send subcommand — completion suggested both.
Now 'pos communication telegram <TAB>' completes to just 'sender' and
'listener'. send is the single canonical action.

- git mv bin/pos-communication-telegram bin/pos-communication-telegram-sender
- remove --send branch + POS_FLAGS entry; add --markdown to completion
- lib/notify.sh: notify_sender_name() maps platform telegram -> telegram-sender
  (notify_send otherwise looks for bin/pos-communication-telegram)
- pos-system-health --send 'sent:' check + pos-entertainment-send use the new
  name and the send subcommand
- completion: keys with nested tools but no direct tool complete to the group
  suffixes (sender/listener); --type/--parse-mode value completion moved to
  the new word positions
- docs updated (POS.md, AGENT_Context, DEV.md, SCRIPTS.md, notify.env,
  HOWTO.md, postinstall.sh); removed phantom webhook/log/broadcast subcommands
  from howto/communication.md
2026-08-09 03:28:30 -04:00

94 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# POS: entertainment send — Run a public-API plugin and send its output via Telegram (default sender)
# POS_FLAGS: --print --markdown
source "$(dirname "$0")/../lib/common.sh" 2>/dev/null || source "$(dirname "$0")/common.sh"
source "$(dirname "$0")/../lib/entertainment-lib.sh" 2>/dev/null || source "$(dirname "$0")/entertainment-lib.sh"
usage() {
local dir plugins
dir="$(plugin_dir 2>/dev/null)" || dir=""
if [ -n "$dir" ]; then
plugins="$(list_plugins "$dir" | sed 's/^/ /')"
else
plugins=" (plugin directory not found — set ENTERTAINMENT_DIR)"
fi
cat <<EOF
Usage: pos entertainment send <plugin> [--print] [--markdown] [plugin args...]
Run an entertainment plugin, capture its output, and send it via Telegram.
Plugins are scripts that fetch a public API and print the message to stdout —
that stdout is what gets sent.
Modes:
(default) Send the plugin output to Telegram (silent)
--print Print the output locally instead of sending
--markdown Send with Markdown parse_mode (via pos communication telegram)
Available plugins:
$plugins
Environment:
ENTERTAINMENT_DIR Override the plugin directory
Config (per plugin): ~/.config/linux_post_install/entertainment.env
Examples:
pos entertainment send weather
pos entertainment send weather --print
pos entertainment send joke --markdown
EOF
exit 0
}
case "${1:-}" in
-h|--help|"") usage ;;
esac
# ── Parse runner flags ──────────────────────────────────────────
PRINT=0
MARKDOWN=0
plugin_args=()
while [ $# -gt 0 ]; do
case "$1" in
--print) PRINT=1; shift ;;
--markdown) MARKDOWN=1; shift ;;
-h|--help) usage ;;
*) plugin_args+=("$1"); shift ;;
esac
done
[ ${#plugin_args[@]} -ge 1 ] || usage
plugin="${plugin_args[0]}"
unset 'plugin_args[0]'
# ── Run the plugin ──────────────────────────────────────────────
dir="$(plugin_dir)"
script="$(resolve_plugin "$dir" "$plugin")"
rc=0
output="$( "$script" "$@" )" || rc=$?
if [ "$rc" -ne 0 ]; then
err "Plugin '$plugin' failed (exit $rc)"
fi
[ -n "$output" ] || { warn "Plugin '$plugin' produced no output — nothing to send"; exit 0; }
# ── Route the output ────────────────────────────────────────────
if [ "$PRINT" -eq 1 ]; then
printf '%s\n' "$output"
exit 0
fi
telegram="$(dirname "$0")/pos-communication-telegram-sender"
[ -x "$telegram" ] || telegram="$(command -v pos-communication-telegram-sender 2>/dev/null || true)"
[ -n "$telegram" ] && [ -x "$telegram" ] || err "pos-communication-telegram-sender not found next to this script"
if [ "$MARKDOWN" -eq 1 ]; then
exec "$telegram" send "$output" --parse-mode markdown
else
exec "$telegram" send "$output"
fi