【问题标题】:AttributeError: module 'google.cloud.dialogflow' has no attribute 'types'AttributeError:模块“google.cloud.dialogflow”没有属性“类型”
【发布时间】:2021-12-30 11:27:50
【问题描述】:

我正在构建一个电报机器人并在其中使用 Dialogflow,我收到以下错误:

2021-11-19 23:26:46,936 - __main__ - ERROR - Update '{'message': {'entities': [], 
'delete_chat_photo': False, 'text': 'hi', 'date': 1637344606, 'new_chat_members': [], 
'channel_chat_created': False, 'message_id': 93, 'photo': [], 'group_chat_created': 
False, 'supergroup_chat_created': False, 'new_chat_photo': [], 'caption_entities': [], 
'chat': {'id': 902424541, 'type': 'private', 'first_name': 'Akriti'}, 
'from': {'first_name': 'Akriti', 'id': 902424541, 'is_bot': False, 'language_code': 'en'}
}, 'update_id': 624230278}' caused error 'module 'google.cloud.dialogflow' has no 
attribute 'types''

似乎 Dialogflow 属性“类型”存在一些问题,但我不知道我做错了什么。

这是我使用它的代码:

import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "client.json"

from google.cloud import dialogflow
dialogflow_session_client = dialogflow.SessionsClient()
PROJECT_ID = "get-informed-ufnl"

from gnewsclient import gnewsclient

client = gnewsclient.NewsClient()


def detect_intent_from_text(text, session_id, language_code='en'):
    session = dialogflow_session_client.session_path(PROJECT_ID, session_id)
    text_input = dialogflow.types.TextInput(text=text, language_code=language_code)
    query_input = dialogflow.types.QueryInput(text=text_input)
    response = dialogflow_session_client.detect_intent(session=session, query_input=query_input)
    return response.query_result



def get_reply(query, chat_id):
    response = detect_intent_from_text(query, chat_id)

    if response.intent.display_name == 'get_news':
        return "get_news", dict(response.parameters)
    else:
        return "small_talk", response.fulfillment_text


def fetch_news(parameters):
    client.language = parameters.get('language')
    client.location = parameters.get('geo-country')
    client.topic = parameters.get('topic')

    return client.get_news()[:5]


topics_keyboard = [
    ['Top Stories', 'World', 'Nation'],
    ['Business', 'Technology', 'Entertainment'],
    ['Sports', 'Science', 'Health']
]

【问题讨论】:

    标签: dialogflow-es telegram-bot python-telegram-bot dialogflow-es-fulfillment


    【解决方案1】:

    我建议停用您当前的错误处理程序或使用类似于this example 的错误处理程序,以便您可以看到异常的完整回溯:)


    免责声明:我目前是python-telegram-bot的维护者

    【讨论】:

    • 感谢您的提示 :)
    【解决方案2】:

    我想通了,问题出在 import 语句上。正确的模块名称应该是:

    import google.cloud.dialogflow_v2 as dialogflow
    

    【讨论】:

      猜你喜欢
      • 2019-07-20
      • 2023-04-06
      • 2010-10-02
      • 2018-04-14
      • 2019-02-18
      • 1970-01-01
      • 2020-01-01
      • 1970-01-01
      相关资源
      最近更新 更多