Skip to content

Instantly share code, notes, and snippets.

@Makopo
Created November 24, 2017 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Makopo/fb47c840f0eaf2289a037c5e993f8423 to your computer and use it in GitHub Desktop.
Save Makopo/fb47c840f0eaf2289a037c5e993f8423 to your computer and use it in GitHub Desktop.
Azure Function - DialogFlow向けwebhoook - followupEventを使ったシンプルな例
#r "Newtonsoft.Json"
using System.Net;
using System.Net.Http.Formatting;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
// 入力データ
dynamic data = await req.Content.ReadAsAsync<object>();
// 返却データ
var responseModel = new ResponseModel()
{
FollowupEvent = new FollowupEventModel()
{
Name = "LOCAL_WEBHOOK_RECEIVED",
Data = new DataModel()
{
Unsei = "大吉"
}
}
};
// シリアライズ化してDialogflowサーバに返す
string json = JsonConvert.SerializeObject(responseModel);
var res = req.CreateResponse(HttpStatusCode.OK);
res.Content = new StringContent(json, Encoding.UTF8, "application/json");
return res;
}
[JsonObject("response")]
public class ResponseModel
{
[JsonProperty("followupEvent")]
public FollowupEventModel FollowupEvent { get; set; }
}
[JsonObject("followupEvent")]
public class FollowupEventModel
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("data")]
public DataModel Data { get; set; }
}
[JsonObject("data")]
public class DataModel
{
[JsonProperty("unsei")]
public string Unsei { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment