图像显示在Dialogflow的默认响应中,但不显示在Facebook Messenger响应中(为什么?)

2024-09-26 18:18:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我创建了一个聊天机器人,并成功地尝试通过卡片响应传递GIF图像。然而,在DialogFlow上可以很好地查看响应,但是聊天机器人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中的输出:

enter image description here

但在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中。代码取自thisSO问题

enter image description here

在Messenger still中,问题仍然存在

enter image description here

然而,当我把一个不同的图像显示成功…这是否重要的gif图像是从驱动器?但是Dialogflow没有任何问题,只有Messenger有

不同的静态图像

enter image description here

更新30.07.2020-基于评论

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

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

导致这种情况的原因是(所以我想仅仅从驱动器共享一个映像是不够的):

enter image description here


Tags: texthttps图像reruncomgetreturntitle
2条回答

搜索6小时后解决:

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

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

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

enter image description here

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

相关问题 更多 >

    热门问题