I created a webhook for my agent, it works fine, I got a successful response from my webhook:
But I got no response in the test chat:
What I need to do to show it in the Default Response?
I was sending the keys with PascalCase, I needed to use camelCase.
So I had to format the settings of the Json.
In Visual Studio (.NET Framework 4.5):
var jsonSerializer = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore
};
return Json(response, jsonSerializer);
Note: In .NET Core, camelCase is default.
Related
I have implemented webhook for revenuecat in .net core C#. But for some reason I am getting 400 badrequest with empty response. I am mostly sure that I am not getting the json response in webook through revenuecat for any of the event occurring.
I have also added endpoint on revenue cat webhook with authentication. I have tried several time and as I have not way to test this on local machine. I need help from revenue cat team to provide some reference doc with sample implementation just to get proper json response. Below is the code snippet that I am using to get json response from the webhook endpoint added in revenuecat.
var webHookSecret = _configuration[Constants.RevenueCatWebHookSecret]; var headerAuthorization = HttpContext.Request.Headers["Authorization"].ToString(); #region Check authorization if (webHookSecret == headerAuthorization) { json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync(); } else { _logger.Information($"Un-Authorized token access in revenuecat webhook. Returning BadRequest response."); throw new APIException(HttpStatusCode.Unauthorized, new APIError(_configuration, "InternalServerError")); }
I have a simple Microsoft Bot where their EchoBot was modified to send proactive messages.
The problem I face is that the Bot depends on the Teams Connector v0.9.0 (latest stable), but when the Bot gets a POST request to its API endpoint, it throws a FileNotFoundException complaining that Teams Connector v1.0.0 is not found.
One problem is that MSFT does not have a v1.0.0 teams connector and furthermore the project was configured for a v0.9.0 dependency.
Does anyone know how I can fix this? I tried publishing from both VS2019 Community on Windows and Mac and get the same result.
Here's the POST endpoint I added to the basic MSFT EchoBot template
[Route("api")]
[HttpPost]
public async Task<IActionResult> Post([FromBody] WebServicePrompt prompt)
{
var message = Activity.CreateMessageActivity();
message.Text = "Hello!";
var conversationParameters = new ConversationParameters
{
IsGroup = true,
ChannelData = new TeamsChannelData
{
Channel = new ChannelInfo(prompt.ChannelId),
},
Activity = (Activity)message
};
var serviceUrl = "https://smba.trafficmanager.net/amer/";
MicrosoftAppCredentials.TrustServiceUrl(serviceUrl, DateTime.Now.AddDays(7));
var account = new MicrosoftAppCredentials("X", "Y");
var connectorClient = new ConnectorClient(new Uri(serviceUrl), account);
var response = await connectorClient.Conversations.CreateConversationAsync(conversationParameters);
// Let the caller know proactive messages have been sent
return new ContentResult()
{
Content = $"Channel ID {prompt.ChannelId}, Response: {response.ToString()}",
ContentType = "text/html",
StatusCode = (int)HttpStatusCode.OK,
};
}
Expected Behavior: MSFT Azure should have identified and found the v0.9.0 dependency. No exception should be thrown and the response should be HTTP 200.
Project Dependencies
Exception Message
I was using Azure Text-to-Speech API succesfully for months with this format:
<speak version='1.0' xmlns='w3.org/2001/10/synthesis' xml:lang='en-US'><voice name='Microsoft Server Speech Text to Speech Voice (fi-FI, HeidiRUS)'>My text</voice></speak>
But suddenly this request started returning:
HTTP/1.1 400 Bad request
We were using the same request successfully for months (with different phrase of course) but just some weeks ago the same request started returning this error. I don't get any additional information so I don't know where to look. Azure documentation says:
A required parameter is missing, empty, or null. Or, the value passed
to either a required or optional parameter is invalid. A common issue
is a header that is too long.
I also tried making the request more specific by adding gender and language and replacing single quotes with double quotes, but no use:
<speak version="1.0" xmlns="w3.org/2001/10/synthesis" xml:lang="fi-FI" xml:gender="Female"><voice name="Microsoft Server Speech Text to Speech Voice (fi-FI, HeidiRUS)">Text.</voice></speak>
Did something change in the API? Or what is missing in my request?
I got a 200 OK with the right content when I send the following payload:
<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'><voice name='Microsoft Server Speech Text to Speech Voice (fi-FI, HeidiRUS)'>This is my test</voice></speak>
Here is my C# code to send this:
// Generate request
string body = $#"<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='{voiceLang}'><voice name='{voiceName}'>{text}</voice></speak>";
using (var client = new HttpClient())
{
using (var request = new HttpRequestMessage())
{
// Set the HTTP method
request.Method = HttpMethod.Post;
// Construct the URI
request.RequestUri = new Uri(ttsHostUri);
// Set the content type header
request.Content = new StringContent(body, Encoding.UTF8, "application/ssml+xml");
// Set additional header, such as Authorization and User-Agent
request.Headers.Add("Authorization", "Bearer " + accessToken);
request.Headers.Add("Connection", "Keep-Alive");
// Update your resource name
request.Headers.Add("User-Agent", "YOUR_RESOURCE_NAME");
request.Headers.Add("X-Microsoft-OutputFormat", "riff-24khz-16bit-mono-pcm");
// Create a request
using (var response = await client.SendAsync(request).ConfigureAwait(false))
{
response.EnsureSuccessStatusCode();
// Asynchronously read the response
using (var dataStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
{
// ... Process your audio here
}
}
}
}
The only difference that I can see on our payloads is the xmlns value where I have a full url (with http://) whereas yours doesn't get it.
The error may be elsewhere: are you sure you are authenticating yourself when querying the endpoint?
We also suddenly got the 400 error and in our case we had missed to encapsulate the text for the XML request with
<![CDATA[ your text here ]]>
after we did that in our code we got no more reported 400 errors by the users.
I'm using the dialogflow Node SDK to send textRequests and eventRequests to dialog flow.
The fulfillment webhook shows that the context is not preserved though the sessionId is the same.
Working with the same dialogflow agent from actions-on-google assistant, the context is preserved.
so the only difference is that i'm using the Node SDK to send the text.
this.app = apiai(CLIENT_ACCESS_TOKEN);
this.options = {
sessionId: 'abc',
originalRequest: {
data: {
user: 'temp_user'
},
conversation: {
"conversationId": "123456789"
}
}
};
const request = this.app.textRequest('This is captured by INTENT_1 that triggers
a webhook that sets context to MY_CONTEXT', options);
const request = this.app.textRequest('This should be captured by INTENT_2
that has an input context of MY_CONTEXT', options);
the second request does not trigger INTENT_2, but the default fallback intent, unless I remove the input context from INTENT_2 in dialogflow and then it's triggered
Might you be using resetContexts by mistake? That would explain it.
I am trying to build a bot using Microsoft Bot Framework. I am planning to use a Azure Function with Http Trigger as the endpoint. NodeJS is the language of my choice. I am seeing botframework examples with restify and nodejs but none on using azure functions. Can anyone point me to an example where botframework is developed using azure functions and nodejs or give me an example on how to do it.
From Chris Anderson...
https://github.com/christopheranderson/functions-bot-example
You'll need to connect it to an HTTP trigger and the following code does the integration.
var listen = bot.listen();
var response = function (context) {
return {
send: function (status, message) {
var _msg = message ? message : (typeof status !== 'number' ? status : null)
var _status = typeof status === 'number' ? status : 200
var res = {
status: _status,
body: _msg
};
context.res = res;
context.done();
}
}
}
module.exports = function (context, req) {
listen(req, response(context))
}
You can see here https://github.com/vjrantal/bot-sample/commit/e80faefded1c9da9a8b0d69e36497bb221b54709 a changeset that brings Azure Functions compatibility to a bot built with restify.
The approach is borrowed from Chris Anderson's project at https://github.com/christopheranderson/functions-bot-example but includes updates to work with the latest botbuilder.
UPDATE: On latest Functions runtime, you don't need the wrapping anymore. See https://github.com/vjrantal/bot-sample/commit/fe56a16f6f0286bfe66095eefc417388c1bc1e1c for details.