我从聊天机器人中的用户那里收到一条消息,其中包含文档形式的附件。我需要识别该文档,将其转换并发送回去。但是首先,我只需要将相同的文档发送给发件人。我该怎么办?
var msg = Message.FromJson(new VkResponse(updates.Object));
try
{
if (msg.Attachments.Count > 0)
{
//
var attachment = msg.Attachments.First();
//
if (attachment.Type == typeof(Document))
{
var doc = attachment.Instance as Document;
var attachments = new List<MediaAttachment>{doc};
//attachments.Add(attachment);
_vkApi.Messages.Send(new MessagesSendParams
{
RandomId = new DateTime().Millisecond,
PeerId = msg.PeerId.Value,
Message = "true",
Attachments = attachments
});
return Ok("ok");
}
else
{
_vkApi.Messages.Send(new MessagesSendParams
{
RandomId = new DateTime().Millisecond,
PeerId = msg.PeerId.Value,
Message = "false"
});
return Ok("ok");
}
}
}
Class Updates.cs:
[Serializable]
public sealed class Updates
{
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("object")]
public JObject Object { get; set; }
[JsonProperty("group_id")]
public long GroupId { get; set; }
}