forked from shellscriptx/shellbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInlineKeyboard.sh
More file actions
executable file
·69 lines (61 loc) · 2.5 KB
/
Copy pathInlineKeyboard.sh
File metadata and controls
executable file
·69 lines (61 loc) · 2.5 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
#
# script: InlineKeyboard.sh
#
# Para melhor compreensão foram utilizados parâmetros longos nas funções; Podendo
# ser substituidos pelos parâmetros curtos respectivos.
# Importando API
source ShellBot.sh
# Token do bot
bot_token='<TOKEN_AQUI>'
# Inicializando o bot
ShellBot.init --token "$bot_token"
ShellBot.username
# Limpa o array que irá receber a estrutura inline_button e suas configurações.
botao1=''
# INLINE_BUTTON - CONFIGURAÇÕES.
#
# Cria e define as configurações do objeto inline_button,
# armazenando-as na variável 'botao1'.
# O parâmetro '-l, --line' determinada a posição do objeto na exibição.
# É possível especificar um ou mais botões na mesma linha. Neste caso
# os serão redimencionados e dispostos em paralelo.
#
# Layout defino abaixo:
#
# [ Blog ] -> linha 1
# [ Telegram (Grupo) ] [ Telegram (Canal) ] -> linha 2
# [ Github ] -> linha 3
#
#
#
# Quando um botão é pressionado o usuário é redirecionado para o endereço configurando em '--url'
ShellBot.InlineKeyboardButton --button 'botao1' --line 1 --text 'Blog' --callback_data '1' --url 'http://shellscriptx.blogspot.com.br' # linha 1
ShellBot.InlineKeyboardButton --button 'botao1' --line 2 --text 'Telegram (Grupo)' --callback_data '3' --url 't.me/shellscript_x' # linha 2
ShellBot.InlineKeyboardButton --button 'botao1' --line 2 --text 'Telegram (Canal)' --callback_data '4' --url 't.me/shellscriptx' # linha 2
ShellBot.InlineKeyboardButton --button 'botao1' --line 3 --text 'Github' --callback_data '5' --url 'https://github.com/shellscriptx' # linha 3
# Cria o objeto inline_keyboard contendo os elementos armazenados na variável 'botao1'
# É retornada a nova estrutura e armazena em 'keyboard1'.
keyboard1="$(ShellBot.InlineKeyboardMarkup -b 'botao1')"
while :
do
# Obtem as atualizações
ShellBot.getUpdates --limit 100 --offset $(ShellBot.OffsetNext) --timeout 30
# Lista o índice das atualizações
for id in $(ShellBot.ListUpdates)
do
# Inicio thread
(
# Verifica se a mensagem enviada pelo usuário é um comando válido.
case ${message_text[$id]} in
"/sigame") # bot comando
# Envia a mensagem anexando o teclado "$keyboard1"
ShellBot.sendMessage --chat_id ${message_chat_id[$id]} --text '*Siga-me*' \
--reply_markup "$keyboard1" \
--parse_mode markdown
;;
esac
) & # Utilize a thread se deseja que o bot responda a várias requisições simultâneas.
done
done
#FIM