maybe someone knows how to do this? For better understanding I have attached screenshots. I am using ASP.NET.
I successfully receive the request, but I don't know how to process it and how to make a response back. For example with message "Test123"
namespace GoogleAsisstantServer.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class GoogleController : ControllerBase
{
[HttpGet]
public IActionResult Get()
{
var result = new Result();
result.Value1 = 123;
return Ok(result);
}
[HttpPost]
public async Task<IActionResult> PostWebHook()
{
string body;
using (var reader = new StreamReader(Request.Body))
{
body = await reader.ReadToEndAsync();
}
return Ok("Test123");
}
}
public class Result
{
public int Value1 { get; set; }
public int Value2 { get; set; }
}
}
How should I process the request here and then return something? For example message "Test123"
This is what I get, but I don't know what to do with it then and send a Response back.
{"handler":{"name":"abc"},"intent":{"name":"actions.intent.MAIN","params":{},"query":"Mit Google sprechen"},"scene":{"name":"actions.scene.START_CONVERSATION","slotFillingStatus":"UNSPECIFIED","slots":{},"next":{"name":"Start_Frage"}},"session":{"id":"ABwppHHVumDrliLJaLSikS6KnIlN7yYv6Z4XJCOYzEZt8Fr08RH6r0wtM2-E0v40lS2p1YosTDfpSCd5Lw","params":{},"typeOverrides":[],"languageCode":""},"user":{"locale":"de-DE","params":{},"accountLinkingStatus":"ACCOUNT_LINKING_STATUS_UNSPECIFIED","verificationStatus":"VERIFIED","packageEntitlements":[],"gaiamint":"","permissions":[],"lastSeenTime":"2021-04-01T10:06:59Z"},"home":{"params":{}},"device":{"capabilities":["SPEECH","RICH_RESPONSE","LONG_FORM_AUDIO"]}}
The request is being sent to you in JSON format. You will need to parse this into an object so that you can use it.
The first thing you are going to need to do is to define the object thats getting retired. This is documented in the request object format.
Very basic example.
public class Handler
{
public string name { get; set; }
}
public class Params
{
public string UserId { get; set; }
public int NumVisits { get; set; }
}
public class Intent
{
public string name { get; set; }
public Params @params { get; set; }
public string query { get; set; }
}
public class Slots
{
}
public class Next
{
public string name { get; set; }
}
public class Scene
{
public string name { get; set; }
public string slotFillingStatus { get; set; }
public Slots slots { get; set; }
public Next next { get; set; }
}
public class Session
{
public string id { get; set; }
public Params @params { get; set; }
public List<object> typeOverrides { get; set; }
public string languageCode { get; set; }
}
public class User
{
public string locale { get; set; }
public Params @params { get; set; }
public string accountLinkingStatus { get; set; }
public string verificationStatus { get; set; }
public List<object> packageEntitlements { get; set; }
public string gaiamint { get; set; }
public List<object> permissions { get; set; }
public DateTime lastSeenTime { get; set; }
}
public class Home
{
public Params @params { get; set; }
}
public class Device
{
public List<string> capabilities { get; set; }
}
public class Response
{
public Handler handler { get; set; }
public Intent intent { get; set; }
public Scene scene { get; set; }
public Session session { get; set; }
public User user { get; set; }
public Home home { get; set; }
public Device device { get; set; }
}
Once you have defined your object you can then Deserialize the request.
var values = JsonSerializer.Deserialize<Response>(body);
As no one has created a library for actions as yet you will need to do this yourself.
Similarly, for the response, you'll need to send back JSON that is formatted using the response object format.