问题
I am using sample12 to create a minimizable webchat on the ServiceNow page. Using sample 12 and building the same, I was able to import it to ServiceNow and get to the point where it appears on a new UI page. But there are two issues 1) CORS 2)Authentication to the BOT isnt happening.
Also, how do I take care of authentication?
I used the following process to host the page
Any ideas ? This sort of embed (as shown below) is working for us. But we need a minimizable webchat on servicenow
回答1:
I now got this working by hosting a app service returning the token. The app is now able to access the BOT.
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.Web.Mvc;
using Newtonsoft.Json.Linq;
using WebApplication1.Controllers;
namespace WebApplication1.Controllers
{
[Route("[controller]/[action]")]
[ApiController]
public class DirectLineController : Controller
{
//[HttpPost]
//public async Task<string> PartialToken()
//{
// string data = await GetToken(false);
// return data;
//}
//[HttpGet]
//public async Task<string> Token()
//{
// string data = await GetToken(true);
// return data;
//}
[HttpPost]
public async Task<string> GetToken()
{
string data = String.Empty;
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",
"Hir-4RmrbUY.cwA.aqo.ojSLtakhThiswontworkdonteventrym64oi_2LE_sB4C5BizQwaCg__q1M");
var response = await client.PostAsync("https://directline.botframework.com/v3/directline/tokens/generate", null);
if (response.IsSuccessStatusCode)
{
var raw = await response.Content.ReadAsStringAsync();
if (true)
{
data = raw;
}
else
{
data = JObject.Parse(raw)["token"].Value<string>();
}
}
}
return data;
}
//protected override void ExecuteCore()
//{
// throw new NotImplementedException();
//}
}
}
来源:https://stackoverflow.com/questions/56834760/bot-framework-sample-12-implementation-on-servicenow