aboutsummaryrefslogtreecommitdiff
path: root/submodules/callback_delete.zsh
blob: 61286ac2314f528a51cc5e0a006749a71bfe7bfc (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Copyright (C) 2024-2025 Maria Lisina
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0

chat_id="$(jq -r '.callback_query.message.chat.id' <<< "${update}")"
message_id="$(jq -r '.callback_query.message.message_id' <<< "${update}")"

if ! output_data="$(
    curl --connect-timeout ${connrefused_timeout} \
        --data-urlencode "chat_id=${chat_id}" \
        --data-urlencode "message_id=${message_id}" \
        --get \
        --max-time ${internal_timeout} \
        --proxy "${internal_proxy}" \
        --retry 1 \
        --retry-connrefused \
        --retry-max-time $((internal_timeout - connrefused_timeout)) \
        --silent \
        --user-agent "${useragent}" \
        "${api_address}/bot${api_token}/deleteMessage"
)"
then
    notification_text="Failed to delete message"

    log_text="deleteMessage (${update_id}): Failed to access Telegram Bot API"
    source "${units}/log.zsh"

    return 0
fi

if ! jq -e '.' <<< "${output_data}" > /dev/null
then
    notification_text="An unknown error occurred"

    log_text="deleteMessage (${update_id}): An unknown error occurred"
    source "${units}/log.zsh"

    return 0
fi

if [[ "$(jq -r '.ok' <<< "${output_data}")" != "true" ]]
then
    notification_text="Failed to delete message"
    error_description="$(jq -r '.description' "${output_file}")"

    if [[ "${error_description}" != "null" ]]
    then
        log_text="deleteMessage (${update_id}): ${error_description}"
    else
        log_text="deleteMessage (${update_id}): An unknown error occurred"
    fi

    source "${units}/log.zsh"
fi