Skip to content

Instantly share code, notes, and snippets.

@shellscriptx
Created February 14, 2019 14:51
Show Gist options
  • Save shellscriptx/b92d16b30135a5def3415aaddec087aa to your computer and use it in GitHub Desktop.
Save shellscriptx/b92d16b30135a5def3415aaddec087aa to your computer and use it in GitHub Desktop.
#!/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