protected void Button3_Click(object sender, EventArgs e) { var bot = new Bot(channelAccessToken); var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.MessageAction() { label = "標題-文字回復", text = "回復文字" }); actions.Add(new isRock.LineBot.UriAction() { label = "標題-開啟URL", uri = new Uri("Http://www.google.com") }); actions.Add(new isRock.LineBot.PostbackAction() { label = "標題-發生postback", data = "abc=aaa&def=111" }); var ButtonTempaleMsg = new isRock.LineBot.ButtonsTemplate() { title = "選項", text = "請選其中之一", altText = "請在手機上檢視", thumbnailImageUrl = new Uri("https://arock.blob.core.windows.net/blogdata201706/22-124357-ad3c87d6-b9cc-488a-8150-1c2fe642d237.png"), actions = actions }; bot.PushMessage(AdminUserId, ButtonTempaleMsg); }
protected void Button3_Click(object sender, EventArgs e) { var bot = new Bot(channelAccessToken); var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.MessageAction() { label = "標題-文字回覆", text = "回覆文字" }); actions.Add(new isRock.LineBot.DateTimePickerAction() { label = "請選擇時間", mode = "datetime" }); actions.Add(new isRock.LineBot.UriAction() { label = "標題-開啟URL", uri = new Uri("https://www.youtube.com/?gl=TW&hl=zh-tw") }); actions.Add(new isRock.LineBot.PostbackAction() { label = "標題-發生postback", data = "abc=aaa&def=111" }); var BottonTempalteMsg = new isRock.LineBot.ButtonsTemplate() { title = "選項", text = "請選擇一個", altText = "請在手機上檢視", thumbnailImageUrl = new Uri("https://voniblog.com/kakao-friends/"), actions = actions }; bot.PushMessage(AdminUserId, BottonTempalteMsg); }
protected void Button3_Click(object sender, EventArgs e) { var bot = new Bot(channelAccessToken); var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.MessageActon() { label = "標題-文字回覆", text = "回覆文字" }); actions.Add(new isRock.LineBot.UriActon() { label = "標題-開啟URL", uri = new Uri("http://www.google.com") }); actions.Add(new isRock.LineBot.PostbackActon() { label = "標題-發生postack", data = "abc=aaa&def=111" }); var ButtonTempalteMsg = new isRock.LineBot.ButtonsTemplate() { title = "選項", text = "請選其中之一", altText = "請在手機上觀看", thumbnailImageUrl = new Uri("https://i.imgur.com/HF5tUXv.jpg"), actions = actions }; bot.PushMessage(AdminUserId, ButtonTempalteMsg); }
protected void Button3_Click(object sender, EventArgs e) { var bot = new Bot(channelAccessToken); var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.MessageAction() { label = "標題-文字回復", text = "回覆文字" }); actions.Add(new isRock.LineBot.UriAction() { label = "標題-開啟URL", uri = new Uri("http://www.google.com") }); actions.Add(new isRock.LineBot.PostbackAction() { label = "標題-發生postback", data = "abc=aaa&def=111" }); var ButtonTemplateMsg = new isRock.LineBot.ButtonsTemplate() { title = "選項", text = "請選擇其中之一", altText = "請在手機上顯示", thumbnailImageUrl = new Uri("https://pics.me.me/which-one-would-you-choose-dream-job-love-of-your-5581703.png"), actions = actions }; bot.PushMessage(AdminUserId, ButtonTemplateMsg); }
protected void Button3_Click(object sender, EventArgs e) { var bot = new Bot(channelAccessToken); //建立actions. 作為ButtonTemplate的用戶回覆行為 var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.MessageAction() { label = "標題-文字回覆", text = "回覆文字" }); actions.Add(new isRock.LineBot.UriAction() { label = "標題-開啟URL", uri = new Uri("http://www.google.com") }); actions.Add(new isRock.LineBot.PostbackAction() { label = "標題-發生postack", data = "abc=aaa&def=111" }); var ButtonTempalteMsg = new isRock.LineBot.ButtonsTemplate() { title = "選項", text = "擇一", altText = "用手機檢視", thumbnailImageUrl = new Uri("https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/d9f94328920441.55d941e2eb7a7.jpg"), actions = actions }; bot.PushMessage(AdminUserId, ButtonTempalteMsg); }
protected void Button4_Click(object sender, EventArgs e) { var bot = new Bot(channelAccessToken); //建立actions,作為ButtonTemplate的用戶回覆行為 var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.MessageActon() { label = "Yes", text = "Yes" }); actions.Add(new isRock.LineBot.MessageActon() { label = "No", text = "No" }); var ConfirmTemplate = new isRock.LineBot.ButtonsTemplate() { title = "選項", altText = "請在手機上檢視", text = "123", actions = actions }; bot.PushMessage(AdminUserId, ConfirmTemplate); }
protected void Button3_Click(object sender, EventArgs e) { var bot = new Bot(channelAccessToken); //建立actions,作為ButtonTemplate的用戶回覆行為 var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.MessageActon() { label = "標題-文字回覆", text = "回覆文字" }); actions.Add(new isRock.LineBot.UriActon() { label = "標題-開啟URL", uri = new Uri("http://www.google.com") }); actions.Add(new isRock.LineBot.PostbackActon() { label = "標題-發生postack", data = "abc=aaa&def=111" }); var ButtonTempalteMsg = new isRock.LineBot.ButtonsTemplate() { title = "選項", text = "請選擇其中之一", altText = "請在手機上檢視", thumbnailImageUrl = new Uri("https://maoup.com.tw/wp-content/uploads/2016/01/160128-1.png"), actions = actions }; bot.PushMessage(AdminUserId, ButtonTempalteMsg); }
protected void Button3_Click(object sender, EventArgs e) { var bot = new Bot(channelAccessToken); //建立actions,作為ButtonTemplate的用戶回覆行為 var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.MessageActon { label = "標題-文字回覆", text = "回覆文字" }); actions.Add(new isRock.LineBot.UriActon() { label = "標題-開啟URL", uri = new Uri("http://www.google.com") }); actions.Add(new isRock.LineBot.PostbackActon() { label = "標題-發生postack", data = "abc=aaa&def=111" }); var ButtonTempalteMsg = new isRock.LineBot.ButtonsTemplate() { title = "選項", text = "請選擇其中之一", altText = "請在手機上檢視", thumbnailImageUrl = new Uri("https://n6.cmsfile.pg0.cn/group1/M00/06/2F/Cgqg2FWcb-eANjr-AARBy8VOjp8861.jpg"), actions = actions }; bot.PushMessage(AdminUserId, ButtonTempalteMsg); }
//樓宇監控模板 public static void BuildingStatusTemplete(ButtonTemplateParameter ButtonTemplateParameter) { var bot = new Bot(channelAccessToken); //建立actions,作為ButtonTemplate的用戶回覆行為 var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.UriAction() { label = "6F 監看", uri = new Uri(ButtonTemplateParameter.ViewURL1) }); actions.Add(new isRock.LineBot.UriAction() { label = "4F 監看", uri = new Uri(ButtonTemplateParameter.ViewURL2) }); //actions.Add(new isRock.LineBot.PostbackAction() //{ label = "空調控制postback", data = "123456789" }); //單一Button Template Message var ButtonTemplate = new isRock.LineBot.ButtonsTemplate() { altText = "監看狀態", text = "樓宇監看", //title = "Title", //設定圖片 thumbnailImageUrl = new Uri("https://cdn0.iconfinder.com/data/icons/linkedin-ui-colored/48/JD-12-512.png"), actions = actions //設定回覆動作 }; //發送 bot.PushMessage(ButtonTemplateParameter.LineID, ButtonTemplate); }
//遠端控制 public static void RemoteController(ButtonTemplateParameter ButtonTemplateParameter) { var bot = new Bot(channelAccessToken); //建立actions,作為ButtonTemplate的用戶回覆行為 var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.PostbackAction() { label = "空調控制postback", data = "123456789" }); //ButtonTemplateParameter.postback.ToString() actions.Add(new isRock.LineBot.MessageAction() { label = "6F 空調", text = ButtonTemplateParameter.LineEvent }); //單一Button Template Message var ButtonTemplate = new isRock.LineBot.ButtonsTemplate() { altText = "監看狀態", text = ButtonTemplateParameter.Title, //title = "Title", //設定圖片 thumbnailImageUrl = new Uri("https://cdn2.iconfinder.com/data/icons/essential-web-5/50/setting-adjust-control-panel-equalizer-256.png"), actions = actions //設定回覆動作 }; //發送 bot.PushMessage(ButtonTemplateParameter.LineID, ButtonTemplate); }
protected void Button_SendButtonTemplate_Click(object sender, EventArgs e) { var bot = new Bot(channelAccessToken); //建立actions,作為ButtonTemplate的用戶回覆行為 var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.MessageAction() { label = "點選這邊等同用戶直接輸入某訊息", text = "/例如這樣" }); actions.Add(new isRock.LineBot.UriAction() { label = "點這邊開啟網頁", uri = new Uri("http://www.google.com") }); actions.Add(new isRock.LineBot.PostbackAction { label = "點這邊發生postack", data = "abc=aaa&def=111" }); //單一Button Template Message var ButtonTemplate = new isRock.LineBot.ButtonsTemplate() { altText = "替代文字(在無法顯示Button Template的時候顯示)", text = "Text", title = "Title", //設定圖片 thumbnailImageUrl = new Uri("https://scontent-tpe1-1.xx.fbcdn.net/v/t31.0-8/15800635_1324407647598805_917901174271992826_o.jpg?oh=2fe14b080454b33be59cdfea8245406d&oe=591D5C94"), actions = actions //設定回覆動作 }; //發送 bot.PushMessage(AdminUserId, ButtonTemplate); }
protected void Button3_Click(object sender, EventArgs e) { var bot = new Bot(channelAccessToken); var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.MessageAction() { label = "Yes", text = "是" }); actions.Add(new isRock.LineBot.UriAction() { label = "url", uri = new Uri("http://www.google.com") }); actions.Add(new isRock.LineBot.PostbackAction() { label = "postack", data = "abc=aaa&def=111" }); var TempalteMessage = new isRock.LineBot.ButtonsTemplate() { title = "選項", text = "請選擇其一", altText = "請在手機上檢視", thumbnailImageUrl = new Uri("https://i.ytimg.com/vi/r3wLrjai_9Q/hqdefault.jpg"), actions = actions }; bot.PushMessage(AdminUserId, TempalteMessage); }
//ButtonsTemplate protected void Button1_Click(object sender, EventArgs e) { var bot = new isRock.LineBot.Bot(channelAccessToken); var ButtonTmpMsg = new isRock.LineBot.ButtonsTemplate() { text = "文字", title = "標題", altText = "替代文字", thumbnailImageUrl = new Uri("https://66.media.tumblr.com/2e37eafc9b6b715ed99b31fb6f72e6a5/tumblr_inline_pjjzfnFy7a1u06gc8_640.jpg") }; //add actions var action1 = new isRock.LineBot.MessageAction() { label = "顯示的標題", text = "呈現的文字" }; ButtonTmpMsg.actions.Add(action1); var action2 = new isRock.LineBot.UriAction() { label = "顯示的標題", uri = new Uri("http://www.google.com") }; ButtonTmpMsg.actions.Add(action2); bot.PushMessage(AdminUserId, ButtonTmpMsg); }
protected void Button3_Click(object sender, EventArgs e) { var bot = new Bot(channelAccessToken); //建立actions,作為ButtonTemplate的用戶回覆行為 var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.MessageActon() { label = "標題-文字回覆", text = "回覆文字" }); actions.Add(new isRock.LineBot.UriActon() { label = "標題-開啟URL", uri = new Uri("http://www.google.com") }); actions.Add(new isRock.LineBot.PostbackActon() { label = "標題-發生postack", data = "abc=aaa&def=111" }); var ButtonTempalteMsg = new isRock.LineBot.ButtonsTemplate() { title = "選項", text = "請選擇其中之一", altText = "請在手機上檢視", thumbnailImageUrl = new Uri("https://cdn.dribbble.com/users/42583/screenshots/4651306/frontlogo-01_1x.png"), actions = actions }; bot.PushMessage(AdminUserId, ButtonTempalteMsg); }
protected void Button3_Click(object sender, EventArgs e) { var bot = new Bot(channelAccessToken); var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.MessageAction() { label = "標題-文字回覆", text = "回復文字" }); actions.Add(new isRock.LineBot.UriAction() { label = "標題-開啟URL", uri = new Uri("http://www.google.com") }); actions.Add(new isRock.LineBot.PostbackAction() { label = "標題-發生Postback", data = "abc=aaa&def=111" }); var ButtonTempalteMsg = new isRock.LineBot.ButtonsTemplate() { title = "選項", text = "請選擇其中之一", altText = "請在手機上檢視", thumbnailImageUrl = new Uri("https://github.com/chunhui1211/BuildSchool2018/blob/master/Bootstrap/Image/S__81010694.jpg?raw=true"), actions = actions }; bot.PushMessage(AdminUserId, ButtonTempalteMsg); }
protected void Button3_Click(object sender, EventArgs e) { var bot = new Bot(channelAccessToken); //建立actions,作為ButtonTemplate的用戶回復行為 var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.MessageAction() { label = "標題-文字回復", text = "回復文字" }); actions.Add(new isRock.LineBot.UriAction() { label = "標題-開啟URL", uri = new Uri("http://www.google.com") }); actions.Add(new isRock.LineBot.PostbackAction() { label = "標題-發生postback", data = "abc=aaa&def=111" }); var ButtonTemplateMsg = new isRock.LineBot.ButtonsTemplate() { title = "選項", text = "請選擇其中之一", altText = "請在手機上檢視", thumbnailImageUrl = new Uri("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSQSfptbc-INs9IUyaBi7xU3_Hr52NbdIEOwOa_gX5xrrQXEd0m7w"), actions = actions }; bot.PushMessage(AdminUserId, ButtonTemplateMsg); }
internal static ButtonsTemplate Make(int QIDnow, int OIDnow, string data) { //建立actions,作為ButtonTemplate的用戶回覆行為 var actions = new List <isRock.LineBot.TemplateActionBase>(); // 以傳進來的QID找到按鈕選項 QuestionDetail questionDetail = new QuestionDetail(QIDnow); List <QuestionDetail> questionDetailList = questionDetail.SelectByQid(); // 以選項的QID跟OID找到button裡要藏的QID和OID (即按下按鈕後下一個出現的QID和OID) for (int i = 0; i < questionDetailList.Count; i++) { NextHelper nextHelper = new NextHelper(questionDetailList[i].QID, questionDetailList[i].OID); QuestionDetail questionDetailNext = nextHelper.GetNext(); actions.Add(new isRock.LineBot.PostbackAction() { label = questionDetailList[i].AnswerOption, data = DateTime.Now.ToString() + $",{questionDetailNext.QID},{questionDetailNext.OID},{data}" }); } // QID 19和29都有四個button了不能加上一步 if (!(QIDnow == 19 || QIDnow == 29)) { // 製作上一步的button PreviousHelper previousHelper = new PreviousHelper(QIDnow, OIDnow); QuestionDetail questionDetailPrevious = previousHelper.GetPrevious(); actions.Add(new isRock.LineBot.PostbackAction() { label = "上一步", data = DateTime.Now.ToString() + $",{questionDetailPrevious.QID}," + $"{questionDetailPrevious.OID},default" }); } //製作模板框架 Question question = new Question(QIDnow); question.SelectByQid(); var ButtonTemplate = new isRock.LineBot.ButtonsTemplate() { altText = $"請使用手機查看喔~{question.QuestionTitle}", //title = question.QuestionTitle, text = question.QuestionText, //設定圖片 thumbnailImageUrl = new Uri(question.ImageUrl), actions = actions //設定回覆動作 }; return(ButtonTemplate); }
protected void Button3_Click(object sender, EventArgs e) { // 建立一個Buttons Template Message 物件 var ButtonsTemplateMsg = new isRock.LineBot.ButtonsTemplate(); // 設定thumbanilImgageUrl ButtonsTemplateMsg.altText = "Kerry 和 Jill 終身大事"; // 無法顯示時的替代文字 ButtonsTemplateMsg.thumbnailImageUrl = new Uri("https://kerrylinebot.azurewebsites.net/Images/user01.jpg"); // 圖片Url ButtonsTemplateMsg.text = "Kerry 和 Jill 終身大事"; ButtonsTemplateMsg.title = "你會來參加嗎?"; // 標題 //建立actions var actions = new List <isRock.LineBot.TemplateActionBase> { new isRock.LineBot.PostbackAction() { label = "會", data = "product=clothes&type=yes" }, new isRock.LineBot.PostbackAction() { label = "不會", data = "product=clothes&type=no" }, new isRock.LineBot.PostbackAction() { label = "考慮中", data = "product=clothes&type=thinking" } }; // 將建立好的actions加入 ButtonsTemplateMsg.actions = actions; // 建立bot instance isRock.LineBot.Bot bot = new Bot(channelAccessToken); // Send ButtonsTemplateMsg using (UserService userService = new UserService()) { //bot.PushMessage(AdminUserId, ButtonsTemplateMsg); var users = userService.GetAll(); if (users.Count > 0) { foreach (var user in users) { bot.PushMessage(user.UserID, ButtonsTemplateMsg); } } } }
protected void Button1_Click(object sender, EventArgs e) { isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken); //建立buttonsTemplate var button = new isRock.LineBot.ButtonsTemplate() { altText = "altText", text = "text", title = "title", thumbnailImageUrl = new Uri("https://i.imgur.com/pAiJpHg.png") }; //actions button.actions.Add(new isRock.LineBot.MessageAction() { label = "美式漢堡", text = "美式漢堡" }); button.actions.Add(new isRock.LineBot.MessageAction() { label = "台灣漢堡", text = "台灣漢堡" }); button.actions.Add(new isRock.LineBot.MessageAction() { label = "熱狗堡", text = "熱狗堡" }); //建立訊息集合(一次發送多則訊息) var msgs = new List <isRock.LineBot.MessageBase>(); //add messages to msgs.Add(new isRock.LineBot.TextMessage("請選擇您喜歡的餐點:")); var ButtonsTmp = new isRock.LineBot.TemplateMessage(button); //quickReply ButtonsTmp.quickReply.items.Add( new isRock.LineBot.QuickReplyDatetimePickerAction( "期望送達時間", "期望送達時間", isRock.LineBot.DatetimePickerModes.time)); //將ButtonsTmp加入msgs msgs.Add(ButtonsTmp); //發送 bot.PushMessage(AdminUserId, msgs); }
internal static ButtonsTemplate MakeDeleteMyPeriodOrderConfirmBtn(int QIDnow, int OIDnow, OrderInfo orderInfo) { //建立actions,作為ButtonTemplate的用戶回覆行為 var actions = new List <isRock.LineBot.TemplateActionBase>(); // 製作Button NextHelper nextHelper = new NextHelper(QIDnow, OIDnow); QuestionDetail questionDetailNext = nextHelper.GetNext(); actions.Add(new isRock.LineBot.PostbackAction() { label = "刪除單一週期性訂單", data = DateTime.Now.ToString() + $",{questionDetailNext.QID},{questionDetailNext.OID},MyOrderPartition" }); actions.Add(new isRock.LineBot.PostbackAction() { label = "刪除完整週期性訂單", data = DateTime.Now.ToString() + $",{questionDetailNext.QID},{questionDetailNext.OID},MyOrder" }); // 製作取消的button CancelHelper cancelHelper = new CancelHelper(QIDnow, OIDnow); QuestionDetail questionDetailCancel = cancelHelper.GetCancel(); actions.Add(new isRock.LineBot.PostbackAction() { label = "取消", data = DateTime.Now.ToString() + $",{questionDetailCancel.QID}," + $"{questionDetailCancel.OID},default" }); //製作模板框架 var ButtonTemplate = new isRock.LineBot.ButtonsTemplate() { altText = $"請使用手機查看喔~", title = "請選擇週期性訂單的刪除範圍", text = $"單一:僅刪除{orderInfo.OrderName}裡{orderInfo.StartTime.ToString("yyyyMMdd")}的訂單,完整:刪除{orderInfo.OrderName}的所有訂單", ////設定圖片 //thumbnailImageUrl = new Uri("https://i220.photobucket.com/albums/dd130/jung_04/p117516087231.jpg"), actions = actions //設定回覆動作 }; return(ButtonTemplate); }
public isRock.LineBot.ButtonsTemplate GetButtonsTemplate(string altText, string text, string title, MessageAction[] _actions) { var actions = new List <TemplateActionBase>(); actions.AddRange(_actions); //單一Button Template Message var ButtonTemplate = new isRock.LineBot.ButtonsTemplate() { altText = altText, text = text, title = title, //設定圖片 thumbnailImageUrl = new Uri("https://orig00.deviantart.net/a350/f/2013/221/7/7/jarvis_rotator_by_yash1331-d6hcqa3.png"), actions = actions //設定回覆動作 }; return(ButtonTemplate); }
internal static ButtonsTemplate DateTimeBtnMake(int QIDnow, int OIDnow, string data) { NextHelper nextHelper = new NextHelper(QIDnow, OIDnow); QuestionDetail questionDetailNext = nextHelper.GetNext(); PreviousHelper previousHelper = new PreviousHelper(QIDnow, OIDnow); QuestionDetail questionDetailPrevious = previousHelper.GetPrevious(); var ButtonTemplate = new isRock.LineBot.ButtonsTemplate(); var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.DateTimePickerAction() { label = "選擇開始日期和時間", mode = "datetime", data = $"{DateTime.Now},{questionDetailNext.QID},{questionDetailNext.OID},start" }); actions.Add(new isRock.LineBot.DateTimePickerAction() { label = "選擇結束日期和時間", mode = "datetime", data = $"{DateTime.Now},{questionDetailNext.QID},{questionDetailNext.OID},end" }); actions.Add(new isRock.LineBot.PostbackAction() { label = "上一步", data = DateTime.Now.ToString() + $",{questionDetailPrevious.QID}," + $"{questionDetailPrevious.OID},default" }); ButtonTemplate = new isRock.LineBot.ButtonsTemplate() { text = "訂單", // title = "選擇日期", //設定圖片 thumbnailImageUrl = new Uri("https://i220.photobucket.com/albums/dd130/jung_04/DateTime.png"), actions = actions }; return(ButtonTemplate); }
//首次登入模板 public static void LoginTemplete(ButtonTemplateParameter ButtonTemplateParameter) { var bot = new Bot(channelAccessToken); //建立actions,作為ButtonTemplate的用戶回覆行為 var actions = new List <isRock.LineBot.TemplateActionBase>(); //actions.Add(new isRock.LineBot.MessageAction() //{ label = "首次登入", text = "首次登入" }); //actions.Add(new isRock.LineBot.MessageAction() //{ label = "點選這邊等同用戶直接輸入某訊息", text = ButtonTemplateFunction.LineEvent }); actions.Add(new isRock.LineBot.UriAction() { label = "首次登入", uri = new Uri("https://ddb9e636.ngrok.io/login.aspx?name=" + ButtonTemplateParameter.LineID) }); //actions.Add(new isRock.LineBot.UriAction() //{ label = "設定推播訊息", uri = new Uri(https://9e90d783.ngrok.io/WebForm1.aspx" + ButtonTemplateParameter.LineID) }); actions.Add(new isRock.LineBot.MessageAction() { label = "設定推播訊息", text = "還沒做好喔@@" }); //單一Button Template Message var ButtonTemplate = new isRock.LineBot.ButtonsTemplate() { altText = "個人設定", text = "Text", //title = "Title", //設定圖片 thumbnailImageUrl = new Uri("https://cdn0.iconfinder.com/data/icons/linkedin-ui-colored/48/JD-12-512.png"), actions = actions //設定回覆動作 }; //發送 bot.PushMessage(ButtonTemplateParameter.LineID, ButtonTemplate); }
public IHttpActionResult POST() { try { //設定ChannelAccessToken(或抓取Web.Config) this.ChannelAccessToken = channelAccessToken; //取得Line Event(範例,只取第一個) var LineEvent = this.ReceivedMessage.events.FirstOrDefault(); isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken); var UserInfo = bot.GetUserInfo(LineEvent.source.userId); //配合Line verify // if (LineEvent.replyToken == "00000000000000000000000000000000") { return(Ok()); } if (LineEvent.type == "postback") { var data = LineEvent.postback.data; var dt = LineEvent.postback.Params.time; this.ReplyMessage(LineEvent.replyToken, $"觸發了 postback \n 資料為:{data}\n 選擇結果:{dt} "); } if (LineEvent.type == "message") { //回覆訊息 //if (LineEvent.message.type == "sticker") //收到貼圖 // this.ReplyMessage(LineEvent.replyToken, 1, 2); if (LineEvent.message.type == "location") //GPS { this.ReplyMessage(LineEvent.replyToken, $"你的位置在\n{LineEvent.message.latitude},{LineEvent.message.longitude}\n{LineEvent.message.address}"); } if (LineEvent.message.type == "text") { if (LineEvent.message.text == "Hello") { this.ReplyMessage(LineEvent.replyToken, UserInfo.displayName + "您好,今天適合穿短袖上衣"); } } if (LineEvent.message.text == "餓了嗎") { var bott = new Bot(channelAccessToken); //建立actions,作為ButtonTemplate的用戶回復行為 var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.MessageAction() { label = "Yes", text = "Yes" }); actions.Add(new isRock.LineBot.MessageAction() { label = "No", text = "No" }); var ConfirmTemplate = new isRock.LineBot.ConfirmTemplate() { text = "請選擇其中之一", altText = "請在手機上檢視", actions = actions }; bott.PushMessage(AdminUserId, ConfirmTemplate); } if (LineEvent.message.text == "Yes") { var bot1 = new Bot(channelAccessToken); //建立actions,作為ButtonTemplate的用戶回復行為 var actions = new List <isRock.LineBot.TemplateActionBase>(); actions.Add(new isRock.LineBot.MessageAction() { label = "標題-文字回復", text = "回復文字" }); actions.Add(new isRock.LineBot.UriAction() { label = "選擇餐廳", uri = new Uri("https://tgifridays.com.tw/locations") }); // actions.Add(new isRock.LineBot.PostbackAction() { label = "標題-發生postback", data = "abc=aaa&def=111" }); actions.Add(new isRock.LineBot.DateTimePickerAction() { label = "請選擇時間", mode = "date" }); var ButtonTemplateMsg = new isRock.LineBot.ButtonsTemplate() { title = "選項", text = "請選擇其中之一", altText = "請在手機上檢視", thumbnailImageUrl = new Uri("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSQSfptbc-INs9IUyaBi7xU3_Hr52NbdIEOwOa_gX5xrrQXEd0m7w"), actions = actions }; bot1.PushMessage(AdminUserId, ButtonTemplateMsg); } if (LineEvent.message.type == "image") { //取得圖片Bytes var bytes = this.GetUserUploadedContent(LineEvent.message.id); //儲存為圖檔 var guid = Guid.NewGuid().ToString(); var filename = $"{guid}.png"; var path = System.Web.Hosting.HostingEnvironment.MapPath("~/Temps/"); System.IO.File.WriteAllBytes(path + filename, bytes); //取得base URL var baseUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority); //組出外部可以讀取的檔名 var url = $"{baseUrl}/Temps/{filename}"; // this.ReplyMessage(LineEvent.replyToken, $"你的圖片位於\n{url}"); var fs1 = new FileStream(path + filename, FileMode.Open); System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(fs1); Graphics g = Graphics.FromImage(bmp); fs1.Close(); var visionClient = new Microsoft.ProjectOxford.Vision.VisionServiceClient(VisionAPIKey, "https://southeastasia.api.cognitive.microsoft.com/vision/v1.0"); //分析圖片(從FileUpload1.PostedFile.InputStream取得影像) //分析 Faces & Description var Results = visionClient.AnalyzeImageAsync(url, new VisualFeature[] { VisualFeature.Faces, VisualFeature.Description }).Result; int isM = 0, isF = 0; foreach (var Face in Results.Faces) { //取得人臉位置 var faceRect = Face.FaceRectangle; //繪製人臉紅框 g.DrawRectangle( new Pen(Brushes.Red, 10), new Rectangle(faceRect.Left, faceRect.Top, faceRect.Width, faceRect.Height)); Font drawFont = new Font("Arial", 40); SolidBrush drawBrush = new SolidBrush(Color.Red); String drawString = Face.Age.ToString(); g.DrawString(drawString + "歲", drawFont, drawBrush, new Point(faceRect.Left - 30, faceRect.Top - 50)); //計算幾男幾女 if (Face.Gender.StartsWith("M")) { isM += 1; } else { isF += 1; } } var path1 = System.Web.Hosting.HostingEnvironment.MapPath("~/Temps/"); var newfilename = Guid.NewGuid().ToString() + ".png"; bmp.Save(path1 + newfilename); this.ReplyMessage(LineEvent.replyToken, new Uri($"{baseUrl}/Temps/{newfilename}")); } } return(Ok()); //this.ReplyMessage(LineEvent.replyToken, "Hello,你的UserId是:" + LineEvent.source.userId); } catch (Exception ex) { //如果發生錯誤,傳訊息給Admin this.PushMessage(AdminUserId, "發生錯誤:\n" + ex.Message); //response OK return(Ok()); } }
public IHttpActionResult webhook() { string ChannelAccessToken = "pm8zf310EYYHjvJEkM347wenUZDiP8IBf/lMfqeoBIroaBQkcyNcg2Me+dQR1lmVDRBPatCB0MjIanxkFa8taRPYX9g+GcmeEuWfz2hf8Gx4SZcxRiYMLcjFVmpw3GhkejYKTkJX/uqjQoDndGNo9wdB04t89/1O/w1cDnyilFU="; try { this.ChannelAccessToken = ChannelAccessToken; string Message = ""; var item = this.ReceivedMessage.events.FirstOrDefault(); isRock.LineBot.Event LineEvent = null; LineUserInfo UserInfo = null; if (item.source.type.ToLower() == "room") { UserInfo = Utility.GetRoomMemberProfile( item.source.roomId, item.source.userId, ChannelAccessToken); } if (item.source.type.ToLower() == "group") { UserInfo = Utility.GetGroupMemberProfile( item.source.groupId, item.source.userId, ChannelAccessToken); } if (item.source.type.ToLower() == "user") { UserInfo = Utility.GetUserInfo(item.source.userId, ChannelAccessToken); } if (item != null) { switch (item.type) { case "join": //Message = $"有人把我加入{item.source.type}中了,大家好啊~"; Message = $"初次見面多多指教,大家好ㄛ~"; //回覆用戶 Utility.ReplyMessage(ReceivedMessage.events[0].replyToken, Message, ChannelAccessToken); break; case "message": int question_id = service.HaveQuestion(item.source.userId); if (question_id != 0) { MessageAction[] actions = null; var msgArray = service.NextQuestion(item.source.userId, ReceivedMessage.events[0].message.text).Split(','); isRock.LineBot.ButtonsTemplate ButtonTemplate = null; switch (msgArray[1]) { case "1": actions = new MessageAction[] { new MessageAction { label = "威秀影城", text = "威秀" }, new MessageAction { label = "國賓影城", text = "國賓" } }; ButtonTemplate = GetButtonsTemplate(msgArray[0], msgArray[0], $"請選擇要查詢之戲院", actions); Utility.ReplyTemplateMessage(item.replyToken, ButtonTemplate, ChannelAccessToken); break; case "2": if (msgArray[2] == "VS") { actions = new MessageAction[] { new MessageAction { label = "京站威秀", text = "京站" }, new MessageAction { label = "信義威秀", text = "信義" }, new MessageAction { label = "日新威秀", text = "日新" }, new MessageAction { label = "板橋大遠百威秀", text = "板橋大遠百" } }; ButtonTemplate = GetButtonsTemplate(msgArray[0], "請點選下方戲院", msgArray[0], actions); Utility.ReplyTemplateMessage(item.replyToken, ButtonTemplate, ChannelAccessToken); } else if (msgArray[2] == "AT") { actions = new MessageAction[] { new MessageAction { label = "西門國賓", text = "西門國賓" }, new MessageAction { label = "威風國賓", text = "威風國賓" }, new MessageAction { label = "長春國賓", text = "長春國賓" }, new MessageAction { label = "中和環球國賓", text = "中和環球國賓" } }; ButtonTemplate = GetButtonsTemplate(msgArray[0], "請點選下方戲院地點(林口國賓、新莊國賓請直接輸入)", msgArray[0], actions); Utility.ReplyTemplateMessage(item.replyToken, ButtonTemplate, ChannelAccessToken); } break; default: Utility.ReplyMessage(item.replyToken, msgArray[0], ChannelAccessToken); break; } } if (item.message.type.ToLower() == "image") { if (imageService.isUploading(item.source.userId)) { var byteArray = Utility.GetUserUploadedContent(item.message.id, ChannelAccessToken); var link = imageService.UploadImage(byteArray, item.source.userId, UserInfo.displayName); isRock.LineBot.TextMessage textMessage = new isRock.LineBot.TextMessage("---Completed!---"); isRock.LineBot.ImageMessage imageMessage = new isRock.LineBot.ImageMessage(new Uri(link), new Uri(link)); var Messages = new List <MessageBase>(); Messages.Add(textMessage); Messages.Add(imageMessage); this.ReplyMessage(item.replyToken, Messages); } } else if (item.message.type.ToLower() == "text") { switch (ReceivedMessage.events[0].message.text) { case "--exit": Utility.ReplyMessage(item.replyToken, "bye-bye", ChannelAccessToken); //離開 if (item.source.type.ToLower() == "room") { Utility.LeaveRoom(item.source.roomId, ChannelAccessToken); } else if (item.source.type.ToLower() == "group") { Utility.LeaveGroup(item.source.groupId, ChannelAccessToken); } break; case "--upload": var msg = imageService.addUploadStatus(item.source.userId); if (!string.IsNullOrEmpty(msg)) { Message = msg; if (UserInfo != null) { Message += $"\r\n -Target user: \"{UserInfo.displayName}\""; } this.ReplyMessage(item.replyToken, Message); } else { Message = "Plz try again. :("; } break; case string str when str.Contains("抽老公") || str.Contains("抽帥哥"): string _url = service.GetRandomGuy(); if (!string.IsNullOrEmpty(_url)) { isRock.LineBot.ImageMessage imageMessage = new isRock.LineBot.ImageMessage(new Uri(_url), new Uri(_url)); var Messages = new List <MessageBase>(); Messages.Add(imageMessage); this.ReplyMessage(item.replyToken, Messages); } else { this.ReplyMessage(item.replyToken, "你沒帥哥或是正在維修中..請洽詢我老闆 :D"); } break; case "-help": Message = "抽帥哥圖片(指令:抽帥哥/抽老公)\r\n========\r\n抽動物圖片(指令:抽動物)\r\n========\r\n查詢地方當前溫度(指令:xx氣溫 / xx溫度)\r\n========\r\n查詢星座今日運勢 (指令:xx座運勢)\r\n========\r\n" + "查詢電影(指令:查詢電影)如果要中斷請輸入\"取消\"\r\n========\r\n近期電影列表(指令:電影列表)"; break; case string str when str.Contains("座運勢"): Message = service.GetHoroscope(str.Substring(0, 3)); break; case string str when str.Contains("電影列表"): Message = service.GetMovieList(); break; case "Hi": Message = "Hello"; break; case string str when str.Contains("抽動物"): string ani_url = "https://" + HttpContext.Current.Request.Url.Host + service.GetAnimalImg(); Utility.ReplyImageMessage(item.replyToken, ani_url, ani_url, ChannelAccessToken); break; case "查詢電影": var question = service.AddQuestion(item.source.userId); if (question != "") { MessageAction[] actions = { new MessageAction { label = "威秀影城", text = "威秀" }, new MessageAction { label = "國賓影城", text = "國賓" } }; var ButtonTemplate = GetButtonsTemplate(question, question, $"{question}", actions); Utility.ReplyTemplateMessage(item.replyToken, ButtonTemplate, ChannelAccessToken); } else { Utility.ReplyMessage(item.replyToken, "請先結束當前問題!", ChannelAccessToken); } break; default: break; } } //取得用戶名稱 //LineUserInfo UserInfo = null; //if (item.source.type.ToLower() == "room") // UserInfo = Utility.GetRoomMemberProfile( // item.source.roomId, item.source.userId, ChannelAccessToken); //if (item.source.type.ToLower() == "group") // UserInfo = Utility.GetGroupMemberProfile( // item.source.groupId, item.source.userId, ChannelAccessToken); //顯示用戶名稱 //if (item.source.type.ToLower() != "user") // Message += "\n你是:" + UserInfo.displayName; //回覆用戶 if (Message != "") { Utility.ReplyMessage(item.replyToken, Message, ChannelAccessToken); } break; default: break; } } } catch (Exception e) { return(Ok(HttpContext.Current.Request.Url.Host)); } return(Ok()); }
//命令列處理 private List <isRock.LineBot.MessageBase> ProcessCommand(isRock.LineBot.Event lineEvent) { //把多格空白換成一個 var cmdLine = MergeSpace(lineEvent.message.text); //取消 / ,以空白做分隔符號,切出 var words = cmdLine.ToLower().Replace("/", "").Split(' ').ToList(); var idOrName = ""; //回覆訊息物件集合 var retMessages = new List <isRock.LineBot.MessageBase>(); //執行api必須的參數 var AzureDevOpsProjectName = ""; var AzureDevOpsOrganizationName = ""; var AzureDevOpsUserPAT = ""; var AzureDevOpsUserName = ""; //如果命令中有 setup if (words.Contains("setup") && words[0] == "setup") { //keep data; System.Web.HttpContext.Current.Application[lineEvent.source.userId] = $"{words[1]},{words[2]},{words[3]},{words[4]}"; //System.Web.HttpContext.Current.Application["AzureDevOpsOrganizationName"] = words[1]; //System.Web.HttpContext.Current.Application["AzureDevOpsProjectName"] = words[2]; //System.Web.HttpContext.Current.Application["AzureDevOpsUserName"] = words[3]; //System.Web.HttpContext.Current.Application["AzureDevOpsUserPAT"] = words[4]; retMessages.Add(new TextMessage("環境參數設定完成!")); return(retMessages); } //取得環境設定 if (System.Web.HttpContext.Current.Application[lineEvent.source.userId] == null) { //缺資料,要求輸入 retMessages.Add(new TextMessage("請先使用 /setup 指令設定環境參數. \n ex. /setup [OrgName] [ProjectName] [UserName] [PAT]")); return(retMessages); } else { var para = System.Web.HttpContext.Current.Application[lineEvent.source.userId].ToString().Split(','); //取得資料 AzureDevOpsProjectName = para[1].Trim(); AzureDevOpsOrganizationName = para[0].Trim(); AzureDevOpsUserPAT = para[3].Trim(); AzureDevOpsUserName = para[2].Trim(); } //取得approvers if (words.Contains("get") && (words.Contains("approver") || words.Contains("approvers"))) { // 建立 AzureDevOpsRestApiClient AzureDevOpsRestApiClient client = new AzureDevOpsRestApiClient( AzureDevOpsUserName, AzureDevOpsUserPAT, AzureDevOpsOrganizationName, AzureDevOpsProjectName); var ret = client.GetApprovers(); if (ret != null & ret.count != 0) { var ButtonsTemplateMsg = new isRock.LineBot.ButtonsTemplate(); var msg = $"共有 { ret.count} 個等待簽核項目..."; ButtonsTemplateMsg.text = msg; ButtonsTemplateMsg.title = "等待簽核項目..."; ButtonsTemplateMsg.thumbnailImageUrl = new Uri("https://i.imgur.com/pAiJpHg.png"); foreach (var item in ret.value) { var action = new isRock.LineBot.MessageAction() { label = $"確定簽核 [編號:{ item.id }]", text = "/Make Approve " + item.id }; ButtonsTemplateMsg.actions.Add(action); msg += $"NO.{ item.id } "; } retMessages.Add(new isRock.LineBot.TextMessage(msg)); retMessages.Add(new isRock.LineBot.TemplateMessage(ButtonsTemplateMsg)); } else { retMessages.Add(new isRock.LineBot.TextMessage($"找不到等待簽核的項目...")); } return(retMessages); } //如果命令中有 start & build if (words.Contains("start") && words.Contains("build")) { //找出build後面的元素 var n = words.FindIndex(c => c == "build"); if (words.Count() >= n) { idOrName = words[n + 1]; } //如果沒有 id, return if (string.IsNullOrEmpty(idOrName)) { return(null); } // 建立 AzureDevOpsRestApiClient AzureDevOpsRestApiClient client = new AzureDevOpsRestApiClient( AzureDevOpsUserName, AzureDevOpsUserPAT, AzureDevOpsOrganizationName, AzureDevOpsProjectName); var BuildId = -1; //如果id不是數字 if (int.TryParse(idOrName, out BuildId) == false) { //取得id(文字)所對應的build definition var Definitions = client.GetDefinitions(); //如果成功取回Definitions if (Definitions != null && Definitions.count > 0) { //找對應名稱的 denifition var Definition = from d in Definitions.value where d.name.ToLower() == idOrName.ToLower() select d; if (Definition != null && Definition.Count() >= 1) { //如果有找到對應名稱的 denifition BuildId = Definition.FirstOrDefault().id; } else { retMessages.Add(new isRock.LineBot.TextMessage($"找不到build {idOrName}")); return(retMessages); } } else { retMessages.Add(new isRock.LineBot.TextMessage($"找不到build Definitions")); return(retMessages); } } //如果找不到build if (BuildId <= -1) { return(null); } var ret = client.QueueNewBuild(BuildId); if (ret != null) { retMessages.Add(new isRock.LineBot.TextMessage($"Build {BuildId} 啟動中... \n Build Name : {ret.definition.name} \n Queue ID : {ret.queue.id} \n buildNumber : {ret.buildNumber}")); } else { retMessages.Add(new isRock.LineBot.TextMessage($"Build {BuildId} 啟動失敗...")); } return(retMessages); } if (words.Contains("make") && words.Contains("approve")) { //找出build後面的元素 var n = words.FindIndex(c => c == "approve"); if (words.Count() >= n) { idOrName = words[n + 1]; } //如果沒有 id, return if (string.IsNullOrEmpty(idOrName)) { return(null); } // 建立 AzureDevOpsRestApiClient AzureDevOpsRestApiClient client = new AzureDevOpsRestApiClient( AzureDevOpsUserName, AzureDevOpsUserPAT, AzureDevOpsOrganizationName, AzureDevOpsProjectName); var ret = client.MakeApprove(int.Parse(idOrName), "ok"); retMessages.Add(new isRock.LineBot.TextMessage($"單據編號 : {ret.id} {ret.status}")); return(retMessages); } //最後沒有任何指令被執行 if (retMessages.Count <= 0) { retMessages.Add(new isRock.LineBot.TextMessage("指令錯誤! 什麼事情都沒發生!")); retMessages.Add(new isRock.LineBot.StickerMessage(1, 2)); } return(retMessages); }
public IActionResult Post() { var AdminUserId = "U8dd73688cf9bd43782e74083c6c372f7"; try { //設定ChannelAccessToken this.ChannelAccessToken = _lineBotConfig.accessToken; //取得Line Event var LineEvent = this.ReceivedMessage.events.FirstOrDefault(); //配合Line verify if (LineEvent == null) { return(Ok()); } if (LineEvent.replyToken == "00000000000000000000000000000000") { return(Ok()); } var responseMsg = ""; //準備回覆訊息 if (LineEvent.type.ToLower() == "message") { if (LineEvent.message.type == "text") { //GoogleShee.SaveMsg(LineEvent.message.text); var ImgTemplist = MyFun.ImgTemplist(); if (LineEvent.message.text.StartsWith("/")) { if (LineEvent.message.text == "/help") { responseMsg = "目前可用關鍵字" + Environment.NewLine + string.Join(Environment.NewLine, ImgTemplist.Select(x => x.Key)) + Environment.NewLine + "/選單" + Environment.NewLine + "/翻成XX" + Environment.NewLine + "/語系"; this.ReplyMessage(LineEvent.replyToken, responseMsg); } else if (LineEvent.message.text == "/選單") { var actions = new List <TemplateActionBase>(); actions.Add(new MessageAction() //MessageAction { label = "倒了", text = "已經倒了" }); actions.Add(new MessageAction() //MessageAction { label = "快倒了", text = "看來是快要倒了" }); actions.Add(new MessageAction() //MessageAction { label = "命不久已", text = "唉唉唉" }); var btn = new isRock.LineBot.ButtonsTemplate { title = "公司倒了嗎", text = "我只是想問公司的情況", thumbnailImageUrl = new Uri("https://i.imgur.com/mm1JcL0.jpg"), actions = actions }; this.ReplyMessage(LineEvent.replyToken, btn); //return Ok(); } else if (LineEvent.message.text == "/語系") { var Languagelist = MyFun.Languagelist().Select(x => x.Key); responseMsg = "目前可翻譯語系" + Environment.NewLine + string.Join(Environment.NewLine, Languagelist); this.ReplyMessage(LineEvent.replyToken, responseMsg); } else if (LineEvent.message.text.StartsWith("/翻成")) { var response = ProcessCommand(LineEvent); if (response != null) { this.ReplyMessage(LineEvent.replyToken, response); } } else if (LineEvent.message.text == "/停止翻譯") { SetState(LineEvent.source.userId, ""); responseMsg = "好的,已停止翻譯"; this.ReplyMessage(LineEvent.replyToken, responseMsg); } else { var ImgTemp = ImgTemplist.Where(x => x.Key == LineEvent.message.text).FirstOrDefault(); if (ImgTemp != null) { this.ReplyMessage(LineEvent.replyToken, ImgTemp.uri); } //responseMsg = $"你說了: {LineEvent.message.text}"; } } else { var MSTranslator = _MSTranslatorlist.Where(x => x.ID == LineEvent.source.userId).FirstOrDefault(); if (MSTranslator != null && !string.IsNullOrEmpty(MSTranslator.language)) { MSTranslatorUtility.MSTranslatorTextKey = _lineBotConfig.MSTranslatorTextKey; var result = MSTranslatorUtility.Translate(LineEvent.message.text.Trim(), GetState(LineEvent.source.userId)); this.ReplyMessage(LineEvent.replyToken, result.FirstOrDefault().translations.FirstOrDefault().text); } } } else if (LineEvent.message.type == "image") { } else { //this.ReplyMessage(LineEvent.replyToken, 11538, 51626501); } } else { //responseMsg = $"收到 event : {LineEvent.type} "; } //回覆訊息 //this.ReplyMessage(LineEvent.replyToken, responseMsg); //response OK return(Ok()); } catch (Exception ex) { //回覆訊息 this.PushMessage(AdminUserId, "發生錯誤:\n" + ex.Message); //response OK return(Ok()); } }
public IHttpActionResult POST() { try { //設定ChannelAccessToken(或抓取Web.Config) this.ChannelAccessToken = channelAccessToken; //取得Line Event(範例,只取第一個) var LineEvent = this.ReceivedMessage.events.FirstOrDefault(); //配合Line verify if (LineEvent.replyToken == "00000000000000000000000000000000") { return(Ok()); } //回覆訊息 if (LineEvent.type == "message") { var repmsg = ""; if (LineEvent.message.type == "text") //收到文字 { //建立 MsQnAMaker Client var helper = new isRock.MsQnAMaker.Client( new Uri(QnAEndpoint), QnAKey); var QnAResponse = helper.GetResponse(LineEvent.message.text.Trim()); var ret = (from c in QnAResponse.answers orderby c.score descending select c ).Take(1); var responseText = UnknowAnswer; if (ret.FirstOrDefault().score > 0) { responseText = ret.FirstOrDefault().answer; } //回覆 this.ReplyMessage(LineEvent.replyToken, responseText); } if (LineEvent.message.type == "sticker") //收到貼圖 { this.ReplyMessage(LineEvent.replyToken, 1, 2); } if (LineEvent.message.text.ToLower().Contains("template message")) { //define actions var act1 = new isRock.LineBot.MessageAction() { text = "test action1", label = "test action1" }; var act2 = new isRock.LineBot.MessageAction() { text = "test action2", label = "test action2" }; var tmp = new isRock.LineBot.ButtonsTemplate() { text = "Button Template text", title = "Button Template title", thumbnailImageUrl = new Uri("https://i.imgur.com/wVpGCoP.png"), }; tmp.actions.Add(act1); tmp.actions.Add(act2); //add TemplateMessage into responseMsgs this.ReplyMessage(new isRock.LineBot.TemplateMessage(tmp)); } } //response OK return(Ok()); } catch (Exception ex) { //如果發生錯誤,傳訊息給Admin this.PushMessage(AdminUserId, "發生錯誤:\n" + ex.Message); //response OK return(Ok()); } }