Fakultas Ilmu Komputer UI

Commit c0e5c58a authored by zakiraihan's avatar zakiraihan
Browse files

Create navigation system for user command

parent 3dfa7903
from flask import Flask, request
from telebot.mastermind import get_response
from navigation.navigation import botNavigation
import telegram
import os
......@@ -17,17 +17,7 @@ app.config.from_object(os.environ.get('APP_SETTINGS'))
def respond():
# retrieve the message in JSON and then transform it to Telegram object
update = telegram.Update.de_json(request.get_json(force=True), bot)
chat_id = update.message.chat.id
msg_id = update.message.message_id
# Telegram understands UTF-8, so encode text for unicode compatibility
text = update.message.text.encode('utf-8').decode()
print("got text message :", text)
response = get_response(text)
bot.sendMessage(chat_id=chat_id, text=response, reply_to_message_id=msg_id)
botNavigation(bot, update)
return 'ok'
@app.route('/setwebhook/<noNgrok>', methods=['GET', 'POST'])
......
from telebot.mastermind import *
def botNavigation(bot, update):
chat_id = update.message.chat.id
msg_id = update.message.message_id
# Telegram understands UTF-8, so encode text for unicode compatibility
text = update.message.text.encode('utf-8').decode()
if (text == "ahoyy"):
basic_response(bot, chat_id)
elif (text == "/about"):
about_response(bot, chat_id)
else :
command_not_found(bot, chat_id, msg_id)
\ No newline at end of file
def get_response(msg):
"""
you can place your mastermind AI here
could be a very basic simple response like "معلش"
or a complex LSTM network that generate appropriate answer
"""
return "Ahoy!!"
\ No newline at end of file
def basic_response(bot, chat_id):
response = "You just inserting the correct command: ahoyy"
bot.sendMessage(chat_id=chat_id, text=response)
def about_response(bot, chat_id):
response = "This is a notification bot for any information system in Fasilkom UI"
bot.sendMessage(chat_id=chat_id, text=response)
def command_not_found(bot, chat_id):
response = "Sorry your command is not in bot"
bot.sendMessage(chat_id=chat_id, text=response, reply_to_message_id=msg_id)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment