Created
November 24, 2017 16:12
-
-
Save Makopo/6e2171443517778405a8fb5d9ce8ab33 to your computer and use it in GitHub Desktop.
DialogFlow(api.ai)向けのシンプルなwebhook
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() | |
{ | |
Speech = "大吉だよ!" | |
}; | |
// シリアライズ化して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("speech")] | |
public string Speech { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment