Skip to content

Instantly share code, notes, and snippets.

@Makopo
Created November 24, 2017 16:12
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Makopo/6e2171443517778405a8fb5d9ce8ab33 to your computer and use it in GitHub Desktop.
DialogFlow(api.ai)向けのシンプルなwebhook
#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