如何获取用户通过Dialog Flow(API.AI)从Facebook Messenger机器人发送的图像/附件? [英] How to get images/attachments sent by user from Facebook messenger bot through Dialog Flow (API.AI)?

查看:69
本文介绍了如何获取用户通过Dialog Flow(API.AI)从Facebook Messenger机器人发送的图像/附件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有由Dialog Flow(API.AI)驱动的Chabot,它要求用户发送图像.

I have Chabot powered by Dialog Flow (API.AI) which requires user to send images.

我知道,当用户单击Messenger中的Get Started按钮(开始与bot对话时)时,会触发带有WELCOME/FACEBOOK_WELCOME事件的Dialog Flow(API.AI)中的意图.

I know that when the user clicks on Get Started button in messenger (while starting a conversation with the bot) an intent in Dialog Flow (API.AI) with WELCOME/FACEBOOK_WELCOME event will get triggered.

当用户发送简单文本消息时,将触发对话框流"(API.AI)中的用户说"中的意图.

When the user sends simple text message an intent in Dialog Flow (API.AI) with that text in User Says will get triggered.

我的疑问是,当用户将图像作为附件发送到bot时,是否会触发Dialog Flow(API.AI)的意图,或者是否有实现这种功能的方法.

My doubt is there any intent in Dialog Flow (API.AI) that gets triggered when a user sends an image as attachment to the bot or is there any methodology to achieve that kind of functionality.

请帮助我

预先感谢

推荐答案

以下是当我将图像作为附件上传到Facebook Messenger时收到的响应.我使用dialogflow.com,并使用AWS Lambda函数,API Gateway和AWS CloudWatch Logs将webhook处理程序集成到nodejs中.您还可以提供Webhook请求并打印日志.编写console.log()确实有助于将从facbook Messenger发送到我们的Webhook的对象打印出来.

Below is the response I get when I upload an image as an attachment on facebook messenger. I used dialogflow.com and integrated my webhook handler in nodejs using AWS Lambda function, API Gateway and AWS CloudWatch Logs. You can also serve webhook request and print logs. Writing console.log() really helped to print the object sent from facbook messenger to our webhook.

exports.handler = (event, context, callback) => {
  console.log(event);
  console.log(event.originalRequest.data.message.attachments[0].payload.url);
};

您将在cloudwatch日志中打印事件对象url: 此处的事件对象中的URL为:

You will get event object url printed in the cloudwatch logs: Here in the event object the url is: https://scontent-ort2-2.xx.fbcdn.net/v/t34.18173-12/30776728_1969968496378460_1504397895_n.png?_nc_cat=0&_nc_ad=z-m&_nc_cid=0&oh=4aad83994a5501d1c50f7e2e6c7d50ea&oe=5ADBEF72

{
    "originalRequest": {
        "source": "facebook",
        "data": {
            "sender": {
                "id": "2037600292946778"
            },
            "recipient": {
                "id": "592499574453638"
            },
            "message": {
                "attachments": [
                    {
                        "payload": {
                            "url": "https://scontent-ort2-2.xx.fbcdn.net/v/t34.18173-12/30776728_1969968496378460_1504397895_n.png?_nc_cat=0&_nc_ad=z-m&_nc_cid=0&oh=4aad83994a5501d1c50f7e2e6c7d50ea&oe=5ADBEF72"
                        },
                        "type": "image"
                    }
                ],
                "mid": "mid.$cAAJAFU4_rqppFAhJFli4sL-nvI2y",
                "seq": 274
            },
            "timestamp": 1524222785882
        }
    },
    "id": "323b2069-1fb3-4643-9cab-a36562286069",
    "timestamp": "2018-04-20T11:13:06.117Z",
    "lang": "en",
    "result": {
        "source": "agent",
        "resolvedQuery": "FACEBOOK_MEDIA",
        "speech": "",
        "action": "",
        "actionIncomplete": false,
        "parameters": {},
        "contexts": [
            {
                "name": "facebook_media",
                "parameters": {},
                "lifespan": 0
            },
            {
                "name": "generic",
                "parameters": {
                    "facebook_sender_id": "2037600292946778"
                },
                "lifespan": 4
            }
        ],
        "metadata": {
            "intentId": "52d18e01-1ff2-4e35-af42-bc2de65fa38b",
            "webhookUsed": "true",
            "webhookForSlotFillingUsed": "false",
            "intentName": "attachment intent"
        },
        "fulfillment": {
            "speech": "Received an image",
            "messages": [
                {
                    "type": 0,
                    "speech": "Received an image"
                }
            ]
        },
        "score": 1
    },
    "status": {
        "code": 200,
        "errorType": "success",
        "webhookTimedOut": false
    },
    "sessionId": "d815740b-4f6d-432b-991d-c1125ceb2665"
}

这篇关于如何获取用户通过Dialog Flow(API.AI)从Facebook Messenger机器人发送的图像/附件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆