我正在尝试使用连接到 Facebook Messenger 的 MS 机器人框架来创建一个简单的演示。该演示将有一个预定义的公司分支机构列表(例如坐标),当用户将他们的位置发送给机器人时(使用 FB Messenger 中的“共享位置”功能),它会调用 Google Maps API 来测量到所有分支机构的距离并找到最近的一个。
但是,我无法获取用户作为附件发送的位置:
//if there is an attachment, assume it's a location
//and print out the attachments count and other info;
if (activity.Attachments != null)
{
int attachmentsCount = activity.Attachments.Count;
await SendReplyToUser(activity.Attachments.Count + " attachments.", activity);
if (attachmentsCount > 0)
{
await SendReplyToUser("I got your attachment! (" + attachmentsCount + ") " +
activity.Attachments[0].Content + "\n\n" + activity.Attachments[0].ContentType + "\n\n" +
activity.Attachments[0].ContentUrl + "\n\n" +
activity.Attachments[0].Name
, activity);
}
return Request.CreateResponse(HttpStatusCode.OK);
}
//otherwise continue processing the user's text message
但是,当我“共享位置”时,附件计数结果为零。如果我发送其他任何东西,比如图片,那么机器人会成功接收到它,但不是位置。我仍然可以确定用户确实发送了附件(否则 activity.Attachments
为空,如果它只是一条短信),但附件计数为零,而且我在activity.Attachments[0]
。
是我做错了什么,还是包含位置的附件被 Facebook 或 MS 机器人框架故意阻止?
最佳答案
该位置实际上在实体集合中,而不是附件集合中。看看那里,您应该会找到您需要的东西。
关于c# - 通过 Facebook Messenger 在 MS bot 框架中接收用户的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38868628/