|
| 1 | +#!/bin/bash |
| 2 | +# script: inlinekeyboard.sh |
| 3 | +# |
| 4 | +# Para melhor compreensão foram utilizados parâmetros longos nas funções; Podendo |
| 5 | +# ser substituídos pelos parâmetros curtos respectivos. |
| 6 | + |
| 7 | +# Importando API |
| 8 | +source ShellBot.sh |
| 9 | + |
| 10 | +# Token do bot |
| 11 | +bot_token='<TOKEN AQUI>' |
| 12 | + |
| 13 | +# Inicializando o bot |
| 14 | +ShellBot.init --token "$bot_token" |
| 15 | +ShellBot.username |
| 16 | + |
| 17 | +# Limpa o array que irá receber a estrutura inline_button e suas configurações. |
| 18 | +unset botao1 |
| 19 | + |
| 20 | +# INLINE_BUTTON - CONFIGURAÇÕES. |
| 21 | +# |
| 22 | +# Cria e define as configurações do objeto inline_button, |
| 23 | +# armazenando-as na variável 'botao1'. |
| 24 | +# O parâmetro '-l, --line' determinada a posição do objeto na exibição. |
| 25 | +# É possível especificar um ou mais botões na mesma linha. Neste caso |
| 26 | +# os serão redimencionados e dispostos em paralelo. |
| 27 | +# |
| 28 | +# Layout defino abaixo: |
| 29 | +# |
| 30 | +# [ Blog ] -> linha 1 |
| 31 | +# [ Telegram (Grupo) ] [ Telegram (Canal) ] -> linha 2 |
| 32 | +# [ Github ] -> linha 3 |
| 33 | +# |
| 34 | +# |
| 35 | +# |
| 36 | +# Quando um botão é pressionado o usuário é redirecionado para o endereço configurando em '--url' |
| 37 | +ShellBot.InlineKeyboardButton --button 'botao1' --line 1 --text 'Blog' --callback_data '1' --url 'http://shellscriptx.blogspot.com.br' # linha 1 |
| 38 | +ShellBot.InlineKeyboardButton --button 'botao1' --line 2 --text 'Telegram (Grupo)' --callback_data '3' --url 't.me/shellscript_x' # linha 2 |
| 39 | +ShellBot.InlineKeyboardButton --button 'botao1' --line 2 --text 'Telegram (Canal)' --callback_data '4' --url 't.me/shellscriptx' # linha 2 |
| 40 | +ShellBot.InlineKeyboardButton --button 'botao1' --line 3 --text 'Github' --callback_data '5' --url 'https://github.com/shellscriptx' # linha 3 |
| 41 | + |
| 42 | +ShellBot.InlineKeyboardButton --button 'botao1' --line 3 --text 'TESTE' --callback_data '5' # linha 3 |
| 43 | + |
| 44 | +# Cria o objeto inline_keyboard contendo os elementos armazenados na variável 'botao1' |
| 45 | +# É retornada a nova estrutura e armazena em 'keyboard1'. |
| 46 | +keyboard1="$(ShellBot.InlineKeyboardMarkup -b 'botao1')" |
| 47 | + |
| 48 | +while : |
| 49 | +do |
| 50 | + # Obtem as atualizações |
| 51 | + ShellBot.getUpdates --limit 100 --offset $(ShellBot.OffsetNext) --timeout 30 |
| 52 | + |
| 53 | + # Lista o índice das atualizações |
| 54 | + for id in $(ShellBot.ListUpdates) |
| 55 | + do |
| 56 | + # Inicio thread |
| 57 | + ( |
| 58 | + # Lê a atualização armazenada em 'id' |
| 59 | + if [ "${update_id[$id]}" ]; then |
| 60 | + |
| 61 | + # Verifica se a mensagem enviada pelo usuário é um comando válido. |
| 62 | + case ${message_text[$id]} in |
| 63 | + "/sigame") # comando do bot |
| 64 | + # Envia a mensagem anexando o teclado "$keyboard1" |
| 65 | + ShellBot.sendMessage --chat_id ${message_chat_id[$id]} --text '*Siga-me*' \ |
| 66 | + --reply_markup "$keyboard1" \ |
| 67 | + --parse_mode markdown |
| 68 | + ;; |
| 69 | + esac |
| 70 | + fi |
| 71 | + ) & # Utilize a thread se deseja que o bot responda a várias requisições simultâneas. |
| 72 | + done |
| 73 | +done |
| 74 | +#FIM |
0 commit comments