示例#1
0
def respond():
    update = telegram.Update.de_json(request.get_json(force=True), bot)

    chat_id = update.message.chat.id

    msg_id = update.message.message_id

    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)

    return 'ok'
示例#2
0
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)

    return 'ok'
示例#3
0
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)
    # get the chat_id to be able to respond to the same user
    chat_id = update.message.chat.id
    # get the message id to be able to reply to this specific message
    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)
    # here we call our super AI
    response = get_response(text)
    # now just send the message back
    # notice how we specify the chat and the msg we reply to
    bot.sendMessage(chat_id=chat_id, text=response, reply_to_message_id=msg_id)

    return 'ok'
示例#4
0
def respond():
    #recuperar el mensaje en JSON y luego transformarlo en el objeto de Telegram
    update = telegram.Update.de_json(request.get_json(force=True), bot)
    # obtener el chat_id para poder responder al mismo usuario
    chat_id = update.message.message_id
    # obtener la identificación del mensaje para poder responder a este mensaje específico
    msg_id = update.message.message_id

    # Telegram entiende UTF-8, así que codifique texto para compatibilidad Unicode
    text = update.message.text.encode('utf-8').decode()
    print("got text message :", text)

    # aquí llamamos a nuestra súper IA
    response = get_response(text)

    # ahora solo envía el mensaje de vuelta
    # observe cómo especificamos el chat y el mensaje al que respondemos
    bot.sendMessage(chat_id=chat_id, text=response, reply_to_message_id=msg_id)
    return 'ok'
示例#5
0
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)
    # get the chat_id to be able to respond to the same user
    chat_id = update.message.chat.id
    # get the message id to be able to reply to this specific message
    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)
    # here we call our super AI
    response = get_response(text)
    if type(response) != type(dict({})):
        bot.sendMessage(chat_id=chat_id,
                        text=response,
                        reply_to_message_id=msg_id)
        return 'OK'
    else:
        response_final = get_location_attributes(response['location'])
        number_of_days = int(response['days'])
        if type(response_final) != type(dict({})):
            bot.sendMessage(chat_id=chat_id,
                            text=str(response_final),
                            reply_to_message_id=msg_id)
            return 'OK'
        else:
            coordinate_dict = response_final['Response']['View'][0]['Result'][
                0]['Location']["NavigationPosition"][0]
            latitude, longitude = coordinate_dict['Latitude'], coordinate_dict[
                'Longitude']
            location_response = requests.get(
                f'https://places.ls.hereapi.com/places/v1/discover/search?at={latitude},{longitude}&r=100000&q'
                f'=Landmark/Attraction&apiKey={secret_key}')
            if location_response.status_code == 200:
                if len(location_response.json()['results']['items']) > 0:
                    tourist_data = location_response.json()
                    tourist_dict = {
                        'title': [],
                        'latitude': [],
                        'longitude': []
                    }
                    for i in range(len(tourist_data['results']['items'])):
                        tourist_dict['title'].append(
                            tourist_data['results']['items'][i]['title'])
                        tourist_dict['latitude'].append(
                            tourist_data['results']['items'][i]['position'][0])
                        tourist_dict['longitude'].append(
                            tourist_data['results']['items'][i]['position'][1])
                    tourist_df = pd.DataFrame(tourist_dict)
                    day_of_travel = fit_and_inference(tourist_df,
                                                      number_of_days)
                    tourist_df['day_of_travel'] = day_of_travel
                    # print(tourist_df)
                    # response = str({'title': list(tourist_df['title']), 'latitude': list(tourist_df['latitude']),
                    #               'longitude': list(tourist_df['longitude']),
                    #                'day_of_travel': list(tourist_df['day_of_travel'])})
                    tourist_df.sort_values(by='day_of_travel',
                                           inplace=True,
                                           axis=0)
                    response = ''.join(
                        f"Place:{tourist_df['title'].iloc[i]} \t Day: {tourist_df['day_of_travel'].iloc[i]}\n"
                        for i in range(len(tourist_df)))

                    bot.sendMessage(chat_id=chat_id,
                                    text=str(response),
                                    reply_to_message_id=msg_id)
                    return 'OK'

                else:
                    bot.sendMessage(chat_id=chat_id,
                                    text='Nothing to roam here captain!',
                                    reply_to_message_id=msg_id)
                    return 'OK'

            else:
                bot.sendMessage(chat_id=chat_id,
                                text='Sorry we faced an error in API',
                                reply_to_message_id=msg_id)
                return 'OK'
示例#6
0
def info(update, context: CallbackContext):
    user_input = update.message.text
    response = get_response(user_input)
    update.message.reply_text("🌏" + response + "🌎")