Skip to content

Instantly share code, notes, and snippets.

@isdaviddong
Created December 11, 2016 05:17
Show Gist options
  • Save isdaviddong/4215c9f835992e6f9fc977b7cd6d0008 to your computer and use it in GitHub Desktop.
Save isdaviddong/4215c9f835992e6f9fc977b7cd6d0008 to your computer and use it in GitHub Desktop.
Line WebHook Example
public class LineChatController : ApiController
{
[HttpPost]
public IHttpActionResult POST()
{
string ChannelAccessToken = "DETqsnH04xR7Xv...(請輸入你自己的ChannelAccessToken)...1cDnyilFU=";
try
{
//取得 http Post RawData(should be JSON)
string postData = Request.Content.ReadAsStringAsync().Result;
//剖析JSON
var ReceivedMessage = isRock.LineBot.Utility.Parsing(postData);
//回覆訊息
string Message;
Message = "你說了:" + ReceivedMessage.events[0].message.text;
//回覆用戶
isRock.LineBot.Utility.ReplyMessage(ReceivedMessage.events[0].replyToken, Message, ChannelAccessToken);
//回覆API OK
return Ok();
}
catch (Exception ex)
{
return Ok();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment