Example #1
0
        public async Task ConfirmStart(string senderId, JObject data)
        {
            var replyToken = data["ReplyToken"].ToString();

            // 忘れるかやめるかの質問を発言
            var templateMessage = new Messages.TemplateMessage
            {
                AltText  = @"せっかく覚えたけど全部忘れるよ?",
                Template = new Templates.ConfirmTemplate
                {
                    Text    = @"せっかく覚えたけど全部忘れるよ?",
                    Actions = new List <Templates.Action>
                    {
                        new Templates.MessageAction
                        {
                            Label = @"忘れて!",
                            Text  = @"忘れて!",
                        },
                        new Templates.MessageAction
                        {
                            Label = @"やめて!",
                            Text  = @"やめて!",
                        },
                    }
                }
            };
            await _lineMessagingService.ReplyMessageAsync(replyToken, templateMessage);
        }
Example #2
0
        public async Task WhoareSelectStart(string senderId, JObject data)
        {
            var filename       = data["Filename"].ToString();
            var faceIds        = data["UnknownFaceIds"];
            var faceRectangles = data["UnknownFaceRectangles"];

            var columns = new List <Templates.CarouselColumn>();

            faceIds
            .Zip(faceRectangles, (faceId, faceRectangle) => new { FaceId = faceId, FaceRect = faceRectangle })
            .Take(5)                                                     // Carousel は最大 5 まで
            .Select((face, index) => new { Face = face, Index = index }) // Face とインデックスを選択
            .ToList()
            .ForEach(face =>
            {
                // 顔の画像ファイルを生成
                var faceFilename        = $"{filename}-{face.Face.FaceId}.jpg";
                var facePreviewFilename = $"{filename}-{face.Face.FaceId}.jpg";
                var faceRectValues      = face.Face.FaceRect.ToString().Split(',');
                var faceRectangle       = new FaceRectangle
                {
                    Left   = int.Parse(faceRectValues[0].ToString()),
                    Top    = int.Parse(faceRectValues[1].ToString()),
                    Width  = int.Parse(faceRectValues[2].ToString()),
                    Height = int.Parse(faceRectValues[3].ToString()),
                };
                CreateFaceImageFile(filename, faceFilename, facePreviewFilename, faceRectangle);

                // CarouselColumn を生成
                columns.Add(new Templates.CarouselColumn
                {
                    Title             = @"この人は誰?",
                    Text              = @"教えて!",
                    ThumbnailImageUrl = $"{_options.GeneratedFilePublicUrlRoot}/{_options.GeneratedFilePublicUrlPath}/{facePreviewFilename}",
                    Actions           = new List <Templates.Action>()
                    {
                        new Templates.PostbackAction
                        {
                            Label = @"この人が誰なのか教える",
                            Data  = $"{face.Index}",
                        },
                        new Templates.PostbackAction
                        {
                            Label = @"やめる",
                            Data  = "Cancel",
                        },
                    },
                });
            });

            // この人たちは誰? を発言
            var templateMessage = new Messages.TemplateMessage
            {
                AltText  = faceIds.Count() == 1 ? @"この人は誰?" : @"この人たちは誰?",
                Template = new Templates.CarouselTemplate
                {
                    Columns = columns,
                }
            };
            await _lineMessagingService.PushMessageAsync(senderId, templateMessage);
        }