Exemplo n.º 1
0
        protected override async Task OnPostbackAsync(PostbackEvent ev)
        {
            ISendMessage replyMessage = new TextMessage("");

            switch (ev.Postback.Data)
            {
            case "Date":
                await messagingClient.ReplyMessageAsync(ev.ReplyToken,
                                                        "You chose the date: " + ev.Postback.Params.Date);

                break;

            case "Time":
                await messagingClient.ReplyMessageAsync(ev.ReplyToken,
                                                        "You chose the time: " + ev.Postback.Params.Time);

                break;

            case "DateTime":
                await messagingClient.ReplyMessageAsync(ev.ReplyToken,
                                                        "You chose the date-time: " + ev.Postback.Params.DateTime);

                break;

            default:
                await SendLineDb(ev.Source.UserId, ev.Postback.Data);

                await messagingClient.ReplyMessageAsync(ev.ReplyToken,
                                                        $"ขอบคุณที่สมัครแจ้งเตือนแอปพลิเคชั่น {ev.Postback.Data} เมื่อเราตรวจพบ Critical เราแจ้งเตือนหาท่านให้เร็วที่สุด หากท่านต้องการยกเลิกติดตามให้พิมพ์ว่า \"unsub\" ขอบคุณครับ");

                break;
            }
        }
Exemplo n.º 2
0
        protected override async Task OnPostbackAsync(PostbackEvent ev)
        {
            switch (ev.Postback.Data)
            {
            case "Date":
                await messagingClient.ReplyMessageAsync(ev.ReplyToken,
                                                        "You chose the date: " + ev.Postback.Params.Date);

                break;

            case "Time":
                await messagingClient.ReplyMessageAsync(ev.ReplyToken,
                                                        "You chose the time: " + ev.Postback.Params.Time);

                break;

            case "DateTime":
                await messagingClient.ReplyMessageAsync(ev.ReplyToken,
                                                        "You chose the date-time: " + ev.Postback.Params.DateTime);

                break;

            default:
                await messagingClient.ReplyMessageAsync(ev.ReplyToken,
                                                        "Your postback is " + ev.Postback.Data);

                break;
            }
        }
Exemplo n.º 3
0
        protected override async Task OnPostbackAsync(PostbackEvent ev)
        {
            log.WriteInfo($"SourceType:{ev.Source.Type}, SourceId:{ev.Source.Id}");

            switch (ev.Postback.Data)
            {
            case "Date":
                await messagingClient.ReplyMessageAsync(ev.ReplyToken,
                                                        "You chose the date: " + ev.Postback.Params.Date);

                break;

            case "Time":
                await messagingClient.ReplyMessageAsync(ev.ReplyToken,
                                                        "You chose the time: " + ev.Postback.Params.Time);

                break;

            case "DateTime":
                await messagingClient.ReplyMessageAsync(ev.ReplyToken,
                                                        "You chose the date-time: " + ev.Postback.Params.DateTime);

                break;

            default:
                await messagingClient.ReplyMessageAsync(ev.ReplyToken,
                                                        "Your postback is " + ev.Postback.Data);

                break;
            }
        }
Exemplo n.º 4
0
        protected override async Task OnPostbackAsync(PostbackEvent ev)
        {
            string text = "";

            switch (ev.Postback.Data)
            {
            case "Date":
                text = "You chose the date: " + ev.Postback.Params.Date;
                break;

            case "Time":
                text = "You chose the time: " + ev.Postback.Params.Time;
                break;

            case "DateTime":
                text = "You chose the date-time: " + ev.Postback.Params.DateTime;
                break;

            default:
                text = "Your postback is " + ev.Postback.Data;
                break;
            }

            dl.Activity sendMessage = new dl.Activity()
            {
                Type = "message",
                Text = text,
                From = new dl.ChannelAccount(ev.Source.Id, ev.Source.Id)
            };

            // Send the message, then fetch and reply messages,
            await dlClient.Conversations.PostActivityAsync(conversationId, sendMessage);

            await GetAndReplyMessages(ev.ReplyToken, ev.Source.Id);
        }
Exemplo n.º 5
0
        protected override async Task OnPostbackAsync(PostbackEvent ev)
        {
            //將 data 資料轉成 QueryString
            var query = HttpUtility.ParseQueryString(ev.Postback.Data);

            if (query["type"] == "search")
            {
                var page = int.Parse(query["page"]);
                var skip = (page - 1) * 5;

                var latitude  = decimal.Parse(query["latitude"]);
                var longitude = decimal.Parse(query["longitude"]);

                var rankList = GetRankList(
                    latitude, longitude, skip);

                var updateTime = rankList
                                 .Where(it => it.properties.updated != "")
                                 .Select(it => new DateTime?(DateTime.Parse(it.properties.updated)))
                                 .FirstOrDefault();

                var flexMessage = GetFlexMessage(rankList, page,
                                                 latitude, longitude, updateTime);

                await _messagingClient.ReplyMessageAsync(ev.ReplyToken,
                                                         new List <ISendMessage> {
                    flexMessage
                });
            }

            if (query["type"] == "map")
            {
                var page = int.Parse(query["page"]);

                var latitude  = decimal.Parse(query["latitude"]);
                var longitude = decimal.Parse(query["longitude"]);

                await _messagingClient.ReplyMessageAsync(ev.ReplyToken,
                                                         new List <ISendMessage> {
                    new TextMessage($"https://fysh711426.github.io/iMaskMap/index.html?latitude={latitude}&longitude={longitude}",
                                    new QuickReply
                    {
                        Items = new List <QuickReplyButtonObject>
                        {
                            new QuickReplyButtonObject(
                                new LocationTemplateAction("查詢")),
                            new QuickReplyButtonObject(
                                new PostbackTemplateAction("重新整理",
                                                           $"type=search&page={page}&latitude={latitude}&longitude={longitude}")),
                            new QuickReplyButtonObject(
                                new PostbackTemplateAction("下一頁",
                                                           $"type=search&page={page+1}&latitude={latitude}&longitude={longitude}")),
                            new QuickReplyButtonObject(
                                new PostbackTemplateAction("口罩地圖",
                                                           $"type=map&page={page}&latitude={latitude}&longitude={longitude}"))
                        }
                    })
                });
            }
        }
Exemplo n.º 6
0
 protected override async Task OnPostbackAsync(PostbackEvent ev)
 {
     //ポストバックイベント
     //Postback event
     //リプライ可能 Replyable
     //https://developers.line.biz/ja/reference/messaging-api/#postback-event
     //https://developers.line.biz/en/reference/messaging-api/#postback-event
 }
Exemplo n.º 7
0
        protected override async Task OnPostbackAsync(PostbackEvent ev)
        {
            // Postback で送信されたデータを共通のモデルクラスに変換
            var animal = JsonConvert.DeserializeObject <Animal>(ev.Postback.Data);

            // icon / nickname switch を使用して返信
            await LineMessagingClient.ReplyMessageAsync(ev.ReplyToken, new List <ISendMessage>
            {
                new TextMessage(
                    animal.Sound, null,
                    new Sender(animal.Name, $"{Environment.GetEnvironmentVariable("ImageBaseUrl")}/{animal.IconFileName}"))
            });
        }
Exemplo n.º 8
0
        protected override async Task OnPostbackAsync(PostbackEvent ev)
        {
            var userId    = ev.Source.UserId;
            var gameEntry = await _tableStorage.FindGameEntryAsync(userId);

            var cardEntry = await _tableStorage.FindCardEntryAsync(userId);

            var replyToken = ev.ReplyToken;

            switch (ev.Postback.Data)
            {
            case "exit":
                await DeleteBingoEntry(replyToken, gameEntry, cardEntry);

                await new BingoMenuManager(_messagingClient).SetStartMenuAsync(userId);
                break;

            case "cancel-exit":
                await _messagingClient.ReplyMessageAsync(replyToken, "キャンセルしました。");

                break;

            case BingoMenuManager.POSTBACK_DATA_START_MENU_HINT:
                await _messagingClient.ReplyMessageAsync(replyToken, ReplyMessage_Usage);

                break;

            case BingoMenuManager.POSTBACK_DATA_GAME_MENU_HINT:
                if (gameEntry?.GameId < 0)
                {
                    await _messagingClient.ReplyMessageAsync(replyToken, ReplyMessage_Start);
                }
                else
                {
                    await _messagingClient.ReplyMessageAsync(replyToken, Help_GameEntry);
                }
                break;

            case BingoMenuManager.POSTBACK_DATA_CARD_MENU_HINT:
                if (cardEntry?.CardId < 0)
                {
                    await _messagingClient.ReplyMessageAsync(replyToken, ReplyMessage_Join);
                }
                else
                {
                    await _messagingClient.ReplyMessageAsync(replyToken, Help_CardCreated);
                }
                break;
            }
        }
Exemplo n.º 9
0
        protected override async Task OnPostbackAsync(PostbackEvent ev)
        {
            var menuList = await MessagingClient.GetRichMenuListAsync();

            var nextMenu = menuList.FirstOrDefault(menu => menu.Name == ev.Postback.Data);

            if (nextMenu == null)
            {
                await MessagingClient.ReplyMessageAsync(ev.ReplyToken, $"Error!! {ev.Postback.Data} not found.");
            }
            await MessagingClient.LinkRichMenuToUserAsync(ev.Source.UserId, nextMenu.RichMenuId);

            await MessagingClient.ReplyMessageAsync(ev.ReplyToken, $"I changed a rich menu to {nextMenu.ChatBarText}");
        }
Exemplo n.º 10
0
        protected override async Task OnPostbackAsync(PostbackEvent ev)
        {
            Log.WriteInfo($"SourceType:{ev.Source.Type}, SourceId:{ev.Source.Id}");

            var data       = JsonConvert.DeserializeAnonymousType(ev.Postback.Data, new { type = "", searchWord = "", location = "" });
            var searchword = Uri.EscapeUriString(Regex.Replace(data.searchWord, "\\s", "+"));

            if (data.type == "keyword")
            {
                await MessagingClient.ReplyMessageAsync(ev.ReplyToken, $"https://www.google.co.jp/maps/search/?api=1&query={data.searchWord}&query={data.location}");
            }
            else
            {
                await MessagingClient.ReplyMessageAsync(ev.ReplyToken, $"https://www.google.co.jp/maps/dir/?api=1&origin={data.location}&destination={searchword}");
            }

            await SourceLocation.UpdateAsync(new EventSourceLocation()
            {
                SourceType = ev.Source.Type.ToString(),
                SourceId   = ev.Source.Id,
                Location   = null
            });
        }
Exemplo n.º 11
0
        protected override async Task OnPostbackAsync(PostbackEvent ev)
        {
            var status = await Status.FindAsync(
                partitionKey : BotStatus.DefaultPartitionKey,
                rowKey : ev.Source.Id);

            switch (ev.Postback.Data)
            {
            case "account link":        //連携開始
                await StartAccountLinkAsync(ev);

                break;

            case "API(UserInfo)":       //連携済みのWebサービスのAPIを利用
                await InvokeWebApiAsync(ev, status);

                break;

            case "Unlink":              //連係解除
                await UnlinkAsync(ev, status);

                break;
            }
        }
Exemplo n.º 12
0
 protected virtual Task HandlePostback(PostbackEvent ev)
 {
     return(Task.CompletedTask);
 }
Exemplo n.º 13
0
 protected virtual Task OnPostbackAsync(PostbackEvent ev) => Task.CompletedTask;
Exemplo n.º 14
0
        private static async Task OnPostbackEventAsync(IDurableOrchestrationClient client, PostbackEvent postbackEvent)
        {
            switch (postbackEvent?.Postback?.Data)
            {
            // テンプレート作成開始
            case "action=startTemplateSetting":
                await lineMessagingClient.ReplyMessageAsync(postbackEvent.ReplyToken,
                                                            new List <ISendMessage>
                {
                    new TextMessage("テンプレートに追加したいセリフを送ってください。")
                });

                await client.StartNewAsync(nameof(MakeTemplate), "tmpl_" + postbackEvent.Source.UserId, null);

                break;

            // テンプレート作成終了
            case "action=endTemplateSetting":
                // Durable Functionsの外部イベントとして送信メッセージを投げる
                await client.RaiseEventAsync("tmpl_" + postbackEvent.Source.UserId, Consts.DurableEventNameAddToTemplate, $"{Consts.FinishMakingTemplate}_{postbackEvent.ReplyToken}");

                break;

            // 翻訳モード選択
            case "action=startTranslation":
                // クイックリプライでモード選択
                await lineMessagingClient.ReplyMessageAsync(postbackEvent.ReplyToken,
                                                            new List <ISendMessage>
                {
                    new TextMessage("何語に翻訳しますか?",
                                    new QuickReply
                    {
                        Items =
                        {
                            new QuickReplyButtonObject(new PostbackTemplateAction(" 英語へ",     "lang=en")),
                            new QuickReplyButtonObject(new PostbackTemplateAction(" 韓国語へ",    "lang=ko")),
                            new QuickReplyButtonObject(new PostbackTemplateAction(" 日本語へ",    "lang=ja")),
                            new QuickReplyButtonObject(new PostbackTemplateAction(" 翻訳モード終了", "action=endTranslation"))
                        }
                    })
                });

                break;

            // 翻訳モード開始
            case string s when s.StartsWith("lang="):
                var lang = s.Replace("lang=", string.Empty);

                await lineMessagingClient.ReplyMessageAsync(postbackEvent.ReplyToken,
                                                            new List <ISendMessage>
                {
                    new TextMessage(
                        @$ "{lang switch
                                {
                                    " en " => " 英語 ",
                                    " ko " => " 韓国語 ",
                                    " ja " => " 日本語 ",
                                    _ => throw new InvalidOperationException()
                                }}に翻訳してしゃべります。")
                });
Exemplo n.º 15
0
        protected override async Task OnPostbackAsync(PostbackEvent ev)
        {
            var query = JsonConvert.DeserializeObject <UserQuery>(ev.Postback.Data);

            await OnBeforePostbackAsync(ev, query);

            if (ShouldEnd)
            {
                return;
            }

            // テキスト・インテント待ちを確認
            var waiterId    = new EntityId(nameof(ContextEntity), $"{WaiterEntityPrefix}_{ev.Source.UserId}");
            var waiterState = await DurableClient.ReadEntityStateAsync <ContextEntity>(waiterId);

            var     isWaitingForIntents = false;
            var     isWaitingForText    = false;
            Context waitingContext      = null;

            if (waiterState.EntityExists && waiterState.EntityState.Context != null)
            {
                waitingContext = waiterState.EntityState.Context;
                if (waitingContext.ExpectedIntentNames != null)
                {
                    isWaitingForIntents = true;
                }
                else
                {
                    isWaitingForText = true;
                }
            }

            // 実行スキルを選択
            var targetSkill = (isWaitingForIntents && waitingContext.ExpectedIntentNames.Contains(query.IntentName)) || isWaitingForText
                ? waitingContext.SkillName  // 待機スキル
                : query.IntentName;         // 解析スキル

            if (isWaitingForText)
            {
                query = new UserQuery
                {
                    IntentName = targetSkill,
                };
            }

            var skill = Skills.FirstOrDefault(s => s.IntentName == targetSkill);

            if (skill != null)
            {
                var requestedTimestamp = query.Timestamp;

                // コンテキスト確認を行う
                var entityId = new EntityId(nameof(ContextEntity), $"{targetSkill}-{ev.Source.UserId}");
                var state    = await DurableClient.ReadEntityStateAsync <ContextEntity>(entityId);

                Context context = null;

                if (state.EntityExists && state.EntityState.Context != null)
                {
                    context = state.EntityState.Context;
                }
                else
                {
                    context = new Context {
                        UserId = ev.Source.UserId, IsNew = true
                    };
                    query.Timestamp = DateTime.UtcNow.Ticks;
                }

                context.UserQuery = query;

                if (!context.UserQuery.IsSubSkill && !context.UserQuery.AllowExternalCalls &&
                    (context.IsNew || context.UserQuery.Timestamp > requestedTimestamp))
                {
                    await LineMessagingClient.ReplyMessageAsync(ev.ReplyToken, "その操作は現在できません。");

                    return;
                }

                // スキル再確認
                var subSkill  = Skills.FirstOrDefault(s => s.IntentName == context.UserQuery.IntentName);
                var execSkill = subSkill ?? skill;

                var messages = await execSkill.GetReplyMessagesAsync(context);

                // 状態を保存
                await DurableClient.SignalEntityAsync <IContextEntity>(entityId, proxy => proxy.SetContext(context));

                // Waiter
                if (context.IsWaiting)
                {
                    await DurableClient.SignalEntityAsync <IContextEntity>(waiterId, proxy => proxy.SetContext(context));
                }

                if (messages != null)
                {
                    if (!execSkill.IsContinued)
                    {
                        var quickReply = await FinishAndGetResumeQuickReplyAsync(context);

                        if (messages.Last().QuickReply != null && messages.Last().QuickReply.Items.Count > 0)
                        {
                            messages.Last().QuickReply = MergeQuickReply(messages.Last().QuickReply, quickReply);
                        }
                        else
                        {
                            messages.Last().QuickReply = quickReply;
                        }
                    }
                    await LineMessagingClient.ReplyMessageAsync(ev.ReplyToken, messages);
                }
                // バッチ実行スキル
                else if (context.UserQuery.SubSkills != null)
                {
                    await StartBatchSubSkills(ev.ReplyToken, context);
                }
            }

            await OnAfterPostbackAsync(ev, query);
        }
Exemplo n.º 16
0
 protected virtual Task OnAfterPostbackAsync(PostbackEvent ev, UserQuery query) => Task.CompletedTask;
Exemplo n.º 17
0
        //自訂解析JSON傳回物件的邏輯
        public override object ReadJson(JsonReader reader, Type objectType,
                                        object existingValue, JsonSerializer serializer)
        {
            JObject jo = JObject.Load(reader);
            //先取得JobType,由其決定建立物件
            string type = jo["type"].ToString();

            switch (type)
            {
            case Event.MESSAGE_TYPE:
                reader = jo["message"].CreateReader();
                MessageConverter messageConverter = new MessageConverter();
                object           message          = messageConverter.ReadJson(reader, typeof(Message), existingValue, serializer);

                MessageEvent mEv = new MessageEvent();
                serializer.Populate(jo.CreateReader(), mEv);
                mEv.Message = (Message)message;
                return(mEv);

            case Event.UNFOLLOW_TYPE:
            case Event.LEAVE_TYPE:
                Event ufEv = new Event(type);
                serializer.Populate(jo.CreateReader(), ufEv);
                return(ufEv);

            case Event.POST_BACK_TYPE:
                PostbackEvent pbEv = new PostbackEvent();
                serializer.Populate(jo.CreateReader(), pbEv);
                return(pbEv);

            case Event.MEMBER_LEAVE_TYPE:
                MemberLeaveEvent mlEv = new MemberLeaveEvent();
                serializer.Populate(jo.CreateReader(), mlEv);
                return(mlEv);

            case Event.MEMBER_JOIN_TYPE:
                MemberJoinEvent mjEv = new MemberJoinEvent();
                serializer.Populate(jo.CreateReader(), mjEv);
                return(mjEv);

            case Event.JOIN_TYPE:
            case Event.FOLLOW_TYPE:
                FollowJoinEvent fEv = new FollowJoinEvent();
                serializer.Populate(jo.CreateReader(), fEv);
                return(fEv);

            case Event.DEVICE_UN_LINK_TYPE:
                DeviceULinkEvent dulEv = new DeviceULinkEvent();
                serializer.Populate(jo.CreateReader(), dulEv);
                return(dulEv);

            case Event.BEACON_TYPE:
                BeaconEvent bEv = new BeaconEvent();
                serializer.Populate(jo.CreateReader(), bEv);
                return(bEv);

            case Event.ACCOUNT_LINK_TYPE:
                AccountLinkEvent alEv = new AccountLinkEvent();
                serializer.Populate(jo.CreateReader(), alEv);
                return(alEv);

            default:
                throw new ApplicationException("Unsupported type: " + type);
            }
        }