【问题标题】:Image is displayed on Default resposnse of Dialogflow but not in Facebook Messenger response (why?)图片显示在 Dialogflow 的默认响应中,但不在 Facebook Messenger 响应中(为什么?)
【发布时间】:2020-07-29 18:24:56
【问题描述】:

我创建了一个聊天机器人,并成功尝试通过卡片响应传递 GIF 图像。但是,在 DialogFlow 上可以很好地查看响应,但 Chatbot Messenger 没有显示任何内容。

这就是我如何称呼我的形象:

# Function 4 --------------------------------------------------------------------------------------------------

def rerun_conversation(req):

    rerun_conversation_text=req.get('queryResult').get('parameters').get('rerun_again')

    if rerun_conversation_text == "No" or rerun_conversation_text == "no":

        return {"fulfillmentMessages": [
            {
      "card": {
        "title": "Enjoy the film",
        "imageUri": "https://lh6.googleusercontent.com/lVo4excFqlywxK4iJ-ITrB0QGZR8ZSF59bL46eXylYCjYRA-8J2YqcSosA-AVE8sdcC2tvnKpUBhlYHS9gu6=w1919-h1007"
      }
    }
  ]
}

    elif rerun_conversation_text == "Yes" or rerun_conversation_text == "yes":

        return {"followupEventInput": {"name": "KellyMovieBot","languageCode": "en-US"}}

Dialogflow 中的输出:

但在 Facebook Messenger 中不返回任何内容

我做了更新 - 29.07.2020 - 22:10


        return {"fulfillmentMessages": [
    {
      "platform": "FACEBOOK",
      "card": {
        "title": "Title: this is a title",
        "subtitle": "This is an subtitle.  Text can include unicode characters including emoji ????.",
        "imageUri": "https://lh6.googleusercontent.com/lVo4excFqlywxK4iJ-ITrB0QGZR8ZSF59bL46eXylYCjYRA-8J2YqcSosA-AVE8sdcC2tvnKpUBhlYHS9gu6=w1919-h1007",
        "buttons": [
          {
            "text": "This is a button",
            "postback": "https://assistant.google.com/"
          }
        ]
      }
    }
  ]
}

这似乎适用于 Facebook Messenger 响应,但图像再次显示在 Dialogflow 中而不是 Facebook Messenger 中。代码取自this SO question。

在 Messenger 中仍然存在问题

但是,当我成功显示不同的图像时...gif图像来自云端硬盘是否重要?但是 Dialogflow 没有任何问题,只有 Messenger 才有。

不同的静态图片

更新 30.07.2020-基于 cmets

更改此图片 uri“https://lh6.googleusercontent.com/lVo4excFqlywxK4iJ-ITrB0QGZR8ZSF59bL46eXylYCjYRA-8J2YqcSosA-AVE8sdcC2tvnKpUBhlYHS9gu6=w1919-h1007”

https://drive.google.com/file/d/1onUvzmNd4cvg4maSA6EpW5uu3py8jYZE/view?usp=sharing

导致了这个(所以我猜只是从驱动器共享图像是不够的):

【问题讨论】:

    标签: python facebook dialogflow-es facebook-messenger dialogflow-es-fulfillment


    【解决方案1】:

    因此,图像响应(包括卡片响应)的基本要求是 URL 应可公开访问。我刚刚检查了您的图片的 URL,它给出了 403 错误。您应该将其公开,然后我想它会起作用。作为附加信息,Facebook 支持以下图像格式:.jpg、.png、静态 gif、动画 gif。如果您的图像不是上述格式之一,则应将其转换。这是您的reference的链接

    【讨论】:

    • 你说得对,除了我的 Gmail 帐户(这两个都将 Dialoflow 与 Google Drive 链接)之外,其他人无法访问它...gif 图像存储在我的驱动器中,我使用了这个 SO 问题 @987654322 @ 使其成为公共 URL。但显然不起作用
    • 创建用于从谷歌驱动器共享图像的公共 URL 应该不难(只需选择单击共享时可以查看的任何人)。您可以使用其他免费的 3rd 方工具,例如 imgur.com 来存储您的图像(非常适合我)。
    • Rhino,我更新了我的问题。显然,图像共享 URL 也不适用于对话流。您能否检查一下您在发布的 URL 中是否有访问权限?
    • 但是来自 imgur.com i.imgur.com/XgmBUUx.gif 的链接对于 dialogflow 的工作方式相同,但对于 Facebook Messenger 则不然
    • 那么,我怀疑你返回FB的json格式已经过时了
    【解决方案2】:

    搜索 6 小时后解决:

    gif 图像应该通过 Image 响应类型而不是卡片传递

            return {
      "fulfillmentMessages": [
        {
          "platform": "FACEBOOK",
          "image": {
            "imageUri": "https://i.imgur.com/XgmBUUx.gif"
          }
        }
      ]
    }
    

    这在 Facebook Messenger 中得到了完美展示!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-19
      • 1970-01-01
      • 1970-01-01
      • 2017-05-10
      • 1970-01-01
      相关资源
      最近更新 更多