Nota:
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
Siga estos pasos para descargar archivos adjuntos desde un bot de Azure en Omnicanal.
Obtenga el token para su bot mediante el ID de la aplicación de Microsoft y el secreto del cliente de su bot.
Obtenga el
attachmentIdde la URL del adjunto.Por ejemplo, si la URL es
https://us-api.asm.skype.com/v1/objects/0-eus-d1-5360689c55c308cb4e3b51722e46b801/, entoncesattachmentIdes0-eus-d1-5360689c55c308cb4e3b51722e46b801.Inserte el
attachmentIden una variableRequestUriy luego useRequestUrien una solicitudGET, así:string requestUri = $"https://botapi.skype.com/amer/v3/attachments/{attachmentId}/views/original"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, requestUri); var authorization = new AuthenticationHeaderValue("bearer", <add the botToken here>); var requestHeaders = new Dictionary<string, string>() { { "Authorization", authorization.ToString() } }; foreach (var header in requestHeaders) { httpRequest.Headers.Add(header.Key, header.Value); } HttpResponseMessage response = await client.SendAsync(httpRequest);
Administrar archivos adjuntos
Nota
La información de esta sección se aplica solo a Government Community Cloud (GCC).
Esta sección describe cómo administrar archivos adjuntos en la plataforma de mensajería del servicio de bot omnicanal.
Primero, revisemos rápidamente los formatos de archivos adjuntos en el canal de servicio de bot omnicanal.
Formatos de datos adjuntos al archivo
Cuando los archivos adjuntos se envían desde Dynamics 365 Contact Center al bot de Azure en el canal del servicio de bots omnicanal, la información necesaria para descargar los archivos se pasa en los campos amsReferences y amsMetadata de la propiedad Activity.ChannelData.
Canal de servicio de bots omnicanal
{
"recipient":{
"id":"8:acs:5ecf37b1-11 Oc-414g-ab33-804ffd6b4a33_eooe0010-7c57-1ceb-nec-113aOdOOb272",
"name":"Omnichannel-test-bot",
"aadObjectId":null,
"role":null
},
"attachments ":null,
"channelData":{
"tags":"Channelld-lcw,FromCustomer",
"deliveryMode":"bridged",
"fromUserId":"8:acs:5ecf37b1-110c-4149-ab33-804ffd6b4a33_00000010-61 b9-ab1 d-3dfe-9c3aOd009ea4",
"amsReferences":[
"0-wus-d6-20e7797d208fab388cc11b09674d166"
],
"amsMetadata":[
{
"contentType":"image/png",
"fileName":"SurnmerTime.png"
}
],
"sourceChannelId":"omnichannel"
}
}
Cómo administrar archivos adjuntos en su código de bot de Azure
La información adjunta se pasa en el canal de servicio del bot omnicanal y se puede acceder a ella en el código del bot, como se muestra en el siguiente ejemplo.
// 1. Retrieve Attachment ID from ChannelData["amsReferences"]
if (turnContext.Activity.ChannelData != null &&
turnContext.Activity.ChannelData is JObject incomingRequestChannelData &&
incomingRequestChannelData.TryGetValue("amsReferences", out JToken amsReferencesArray))
{
string attachmentId = JsonConvert.DeserializeObject<string[]>(amsReferencesArray.ToString()).FirstOrDefault();
// 2. Build HTTP request for specified attachment ID.
string requestUri = $"https://botapi.skype.com/amer/v3/attachments/{attachmentId}/views/original";
var httpRequest = new HttpRequestMessage(HttpMethod.Get, requestUri);
// 3. Acquire authentication token and add it to request headers
var token = await new MicrosoftAppCredentials("botAppId", "botAppSecret").GetTokenAsync();
var authorization = new AuthenticationHeaderValue("bearer", token);
httpRequest.Headers.Add("Authorization", authorization.ToString());
// 4. Add Azure Communication Services Bot ID to request header. This is required to achieve good download performance.
httpRequest.Headers.Add("BotAcsId", turnContext.Activity.Recipient.Id);
// 5. Use HttpClient to execute the request and download attachment
var response = await client.SendAsync(httpRequest);
// 6. Save HTTP response stream to the file
var responseContentStream = await response.Content.ReadAsStreamAsync();
using (FileStream fileCreateStream = new FileStream("file path", FileMode.Create))
{
fileCreateStream.CopyTo(responseContentStream);
}
}
Información relacionada
Soporte de tarjeta por canal
Soporte para chat en vivo y canales asincrónicos