


# x telegram bot sub "<botid-url-...>" "<user?-topic?-group?>"

# x telegram bot sub

___x_cmd_telegram_bot_sub(){
    local url="https://api.telegram.org/$1/getUpdates"
    local timeout=100

    local fp="$___X_CMD_ROOT_DATA/telegram/data.json"
    ___x_cmd ensurefp "$fp"

    local offset;   offset="$(x jq ".result[-1].update_id + 1" "$fp" )"
    offset="${offset:-1}"
    x:info "Fetching msg from $offset"

    ___x_cmd jo dict "offset=${offset}" "timeout=${timeout}"  | \
        ___x_cmd curl -s -X POST -H 'Content-Type: application/json'  -d @- "$url" | \
        ___x_cmd jq -c | \
        ___x_cmd tee "$fp"
}
