Beispiel #1
0
        public async Task <IList <ResponseRichMenu> > CreateRichMenuAsync(bool isRefresh)
        {
            var menuList = await MessagingClient.GetRichMenuListAsync();

            if (isRefresh)
            {
                await DeleteRichMenusAsync(menuList);
            }
            var newMenuList = new List <ResponseRichMenu>();

            newMenuList.Add(await RegisterRichMenuAsync(RichMenuA));
            newMenuList.Add(await RegisterRichMenuAsync(RichMenuB));
            newMenuList.Add(await RegisterRichMenuAsync(RichMenuC));
            newMenuList.Add(await RegisterRichMenuAsync(RichMenuD));
            return(newMenuList);

            async Task <ResponseRichMenu> RegisterRichMenuAsync(RichMenu newItem)
            {
                var item = menuList.FirstOrDefault(menu => menu.Name == newItem.Name);

                if (item == null)
                {
                    var id = await MessagingClient.CreateRichMenuAsync(newItem);

                    var image = CreateRichMenuImage(newItem);
                    await UploadRichMenuImageAsync(image, id);

                    item = newItem.ToResponseRichMenu(id);
                }
                return(item);
            }
        }