Created
November 24, 2017 16:17
-
-
Save Makopo/fb47c840f0eaf2289a037c5e993f8423 to your computer and use it in GitHub Desktop.
Azure Function - DialogFlow向けwebhoook - followupEventを使ったシンプルな例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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