Hangouts Chat - 使用 Pub/Sub 时授权访问第三方服务

Hangouts Chat - Authorizing access to third party services when using Pub/Sub

文档 (https://developers.google.com/hangouts/chat/how-tos/auth-3p) 建议向用户发送直接消息('REQUEST_CONFIG' 类型):

Bots that use Cloud Pub/Sub endpoints cannot use this method that involves an HTTP response, because they aren't able to respond synchronously. Instead, they should implement a similar flow, but by asynchronously sending a direct message back to the user using Message.create.

Message.create 需要 space 名称。如果我回复的原始消息发布在房间中,我如何找到直接消息的 space 名称?

截至目前,直接 DM 用户的唯一方法是让用户先添加机器人。要在原始消息在房间中时向用户发送消息,工作流程可能如下所示:

  1. 想要使用bot的用户必须提前直接给bot发消息
  2. 您可以将 space_id 和 user.displayName 存储到数据库中
  3. 机器人可以在 space 中看到消息,并直接向使用机器人查询数据库的用户发送消息 space_id。
  4. 如果用户不在数据库中,bot 可以@mention 用户提示他使用
  5. 直接 dm 机器人