Home > Back-end >  How to send a message with button in shell to Telegram bot?
How to send a message with button in shell to Telegram bot?

Time:02-25

I'm using this and works. But how to put a button blew the message? I tried a lot and still got no idea.

Sorry i forgot to tell it's about Telegram bot api. I want to send a message with button blew.

function sendadmin(){
    if [ "$admin_id" -ne "$chat_id" ]; then
        curl -s \
        -d parse_mode="MarkdownV2" \
        -d text="$stext" \
        -d chat_id="$admin_id" \
        -d -sendChatAction="videos" \
        -d reply_markup="" \
        https://api.telegram.org/bot$bot_token/sendMessage
    fi
}

stext="||Hello darling||"
sendadmin

I tried solution of this. And it's return Bad Request: can't parse reply keyboard markup JSON object error.

CodePudding user response:

reply=$(cat <<-EOF
{
    "inline_keyboard": [
        [
            {
                "text": "Button1",
                "callback_data": "lt"
            },
            {
                "text": "Button1",
                "callback_data": "rt"
            }
        ],
        [
            {
                "text": "Button3",
                "callback_data": "ls"
            }
        ]
    ]
}
EOF
)

Using car <<EOF EOF to give that json format to a variable and then use it like reply_markup="$reply" . I just found out this way.

  • Related