Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Seguire questa procedura per scaricare gli allegati da un bot di Azure in Omnichannel.
Ottieni il token per il tuo bot usando l'ID app Microsoft del bot e il segreto del cliente.
Ottieni l'oggetto
attachmentIddall'URL dell'allegato.Ad esempio, se l'URL è
https://us-api.asm.skype.com/v1/objects/0-eus-d1-5360689c55c308cb4e3b51722e46b801/, èattachmentId0-eus-d1-5360689c55c308cb4e3b51722e46b801.Inserire in
attachmentIdunaRequestUrivariabile e quindi usareRequestUriin unaGETrichiesta, come illustrato di seguito: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);
Gestire gli allegati di file
Annotazioni
Le informazioni contenute in questa sezione sono applicabili solo a Government Community Cloud (GCC).
Questa sezione descrive come gestire gli allegati di file nella piattaforma di messaggistica del servizio bot Omnichannel.
Prima di tutto, esaminiamo rapidamente i formati degli allegati di file nel canale del servizio bot Omnichannel.
Formati di file allegati
Quando gli allegati di file vengono inviati da Dynamics 365 Contact Center al bot di Azure nel canale del servizio bot Omnichannel, le informazioni necessarie per il download dei file vengono passate nei campi amsReferences e amsMetadata della proprietà Activity.ChannelData.
Canale del servizio bot Multicanale
{
"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"
}
}
Come gestire gli allegati di file nel codice del bot di Azure
Le informazioni sugli allegati vengono passate nel canale del servizio bot Omnichannel e sono accessibili nel codice del bot, come illustrato nell'esempio seguente.
// 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);
}
}
Informazioni pertinenti
Supporto card per canale
Supporto per chat live e canali asincroni