iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 8
0
Modern Web

宅男的浪漫 - 用 .NET Core 打造 Line 婚禮聊天機器人經驗分享系列 第 8

一鍵導航婚宴地點辦在哪

第12 屆iT邦幫忙鐵人賽系列文章 (Day8)

籌備婚禮期間甚至婚禮當天(暈),常常被問的就是問地點在哪了,Line 本身能直接傳送地圖資訊,可以直接引導到 Google Map 進行導航,在 Line 可以透過 LocationMessage 發送

定義 LocationMessage.cs

public class LocationMessage : IMessage

{

public LineMessageType Type => LineMessageType.location;

public string Title { get; set; }

public string Address { get; set; }

public decimal Latitude { get; set; }

public decimal Longitude { get; set; }

}

假設我們今天辦在東方文華 (當然沒那麼有錢)

地址為 台灣台北市敦化北路 158 號

經緯度可以在 google map 看到為 @25.0557416,121.5481485

實作 WeddingLocation.cs

public async Task ReplyAsync(string replyToken)

{

var locationName = "臺北文華東方酒店";

var msg = new TextMessage()

{

Text = $"我們在 {locationName} 舉辦唷!"

};

var locationMessage = new LocationMessage()

{

Title = $"Kyle's Wedding - {locationName}",

Address = "台灣台北市敦化北路 158 號",

Latitude = Convert.ToDecimal(25.0557416),

Longitude = Convert.ToDecimal(121.5481485)

};

await lineMessageUtility.ReplyMessageAsync(replyToken, new List<IMessage> {

msg,

locationMessage

});

}

OnMessageAsync

protected virtual async Task OnMessageAsync(Event ev)

{

if (ev.message.Type.Equals(LineMessageType.text))

{

// 完整比對使用者輸入的訊息,決定要回傳什麼

var msg = ev.message.Text;

var intents = new Dictionary<string, IReplyIntent>()

{

{ "電子喜帖" ,new WeddingInvitation(lineMessageUtility,lineProfileUtility)},

{ "前導影片" ,new WeddingTrailer(lineMessageUtility,lineProfileUtility)},

{ "婚宴地點" ,new WeddingLocation(lineMessageUtility,lineProfileUtility)},

{ "Default" ,new DefaultIntent(lineMessageUtility,lineProfileUtility)},

};

var intent = intents.ContainsKey(ev.message.Text) ? intents[msg] : intents["Default"];

await intent.ReplyAsync(ev.replyToken);

}

}

實作效果

懶人包,本次學到了什麼?

本篇文章同步發佈於我的 Medium 如果這篇文章對你有幫助,就大力追蹤和拍手鼓掌下去吧 !!


上一篇
有聲有色,傳送婚禮前導預告影片
下一篇
來做一些婚紗輪播
系列文
宅男的浪漫 - 用 .NET Core 打造 Line 婚禮聊天機器人經驗分享30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言