Created
February 14, 2019 14:51
-
-
Save shellscriptx/b92d16b30135a5def3415aaddec087aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Importando API | |
source ShellBot.sh | |
# Token do bot | |
bot_token='<TOKEN_AQUI>' | |
# Inicializando o bot | |
ShellBot.init --token "$bot_token" --flush --monitor --return map | |
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 | |
# Comando. | |
/cmd) | |
# Envia pergunta. | |
ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \ | |
--text 'Comando:' \ | |
--reply_markup "$(ShellBot.ForceReply)" # Força resposta. | |
;; | |
esac | |
# Verifica se há resposta. | |
if [[ ${message_reply_to_message_message_id[$id]} ]]; then | |
# Se a resposta é referente a pergunta. | |
if [[ ${message_reply_to_message_text[$id]} == Comando: ]]; then | |
ShellBot.sendMessage --chat_id ${message_chat_id[$id]} \ | |
--text "**Resposta:** ${message_text[$id]}" \ | |
--parse_mode markdown | |
fi | |
fi | |
) & # Utilize a thread se deseja que o bot responda a várias requisições simultâneas. | |
done | |
done | |
#FIM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment