环聊聊天API返回400以创建类型为actionResponse的消息

问题描述

我试图使用聊天python client发布消息。请求正文应为https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.messages?hl=zh-cn#Message类型。

这是我的示例代码

    def callback(message):
    logging.info('Received message: %s',message.data)

    event = json.loads(message.data)
    space_name = event['space']['name']

    # If the bot was removed,we don't need to return a response.
    if event['type'] == 'REMOVED_FROM_SPACE':
        logging.info('Bot removed rom space %s',space_name)
        return

    # response = format_response(event)
    response = {'actionResponse': {'type': 'REQUEST_CONfig','url': 'https://google.com'}}
    
    # Send the asynchronous response back to Hangouts Chat
    chat.spaces().messages().create(
        parent=space_name,body=response).execute()
    message.ack()

我收到此错误

E2020-08-14 21:43:08,632 streaming_pull_manager.py:82] Top-level exception occurred in callback while processing a message
Traceback (most recent call last):
  File "/Users/kasi/repos/hangouts-chat-samples/python/pub-sub-bot/env/lib/python3.8/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py",line 77,in _wrap_callback_errors
    callback(message)
  File "bot.py",line 59,in callback
    chat.spaces().messages().create(
  File "/Users/kasi/repos/hangouts-chat-samples/python/pub-sub-bot/env/lib/python3.8/site-packages/googleapiclient/_helpers.py",line 134,in positional_wrapper
    return wrapped(*args,**kwargs)
  File "/Users/kasi/repos/hangouts-chat-samples/python/pub-sub-bot/env/lib/python3.8/site-packages/googleapiclient/http.py",line 917,in execute
    raise HttpError(resp,content,uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://chat.googleapis.com/v1/spaces/1YIkLgAAAAE/messages?alt=json returned "Message cannot be empty.">

如果我在响应中添加文本字段,则漫游器响应消息与简单文本答复完全相同。对于以下给定的响应主体。

        response = {
        'actionResponse': {
            'type': 'REQUEST_CONfig','url': 'https://google.com'
        },'text': 'This is a text','thread': {'name': 'spaces/AAAAiu7EpR8/threads/4wRxupjMbbk'}
    }

我收到的不是私人消息。

enter image description here

我期望的是

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)