示例#1
0
        private async Task <string> SearchCharacter(Activity activity, Activity reply)
        {
            string newCharacter = activity.Text;

            //https://stackoverflow.com/a/5788920/294804
            var parameters = new CharacterParam(Resources.PrivateKey, Resources.PublicKey)
            {
                Name = newCharacter
            };

            var section = "characters";
            //https://stackoverflow.com/a/14517976/294804
            var uriBuilder = new UriBuilder($"http://gateway.marvel.com/v1/public/{section}")
            {
                Query = parameters.ToString()
            };
            var basicUrl = uriBuilder.ToString();

            HttpClient request        = new HttpClient();
            var        responseString = await request.GetStringAsync(basicUrl);

            var serializedEntity = JsonConvert.DeserializeObject <Response <Character> >(responseString);

            selectedCharacterId = serializedEntity.Data.Results[0].Id.ToString();
            string name    = serializedEntity.Data.Results[0].Name;
            string content = await Translator.TranslateSentenceAsync(serializedEntity.Data.Results[0].Description, languageCode);

            var      thumbnail = serializedEntity.Data.Results[0].Thumbnail;
            HeroCard myCard    = await HeroCardCreation(name, content, thumbnail);

            reply.Attachments.Add(myCard.ToAttachment());
            return(newCharacter);
        }
示例#2
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            var    activity     = await result as Activity;
            string newCharacter = activity.Text;

            //https://stackoverflow.com/a/5788920/294804
            var parameters = new CharacterParam(Resources.PrivateKey, Resources.PublicKey)
            {
                Name = newCharacter
            };

            var section = "characters";
            //https://stackoverflow.com/a/14517976/294804
            var uriBuilder = new UriBuilder($"http://gateway.marvel.com/v1/public/{section}")
            {
                Query = parameters.ToString()
            };
            var basicUrl = uriBuilder.ToString();

            HttpClient request        = new HttpClient();
            var        responseString = await request.GetStringAsync(basicUrl);

            var    serializedEntity = JsonConvert.DeserializeObject <Response <Character> >(responseString);
            string name             = serializedEntity.Data.Results[0].Name;
            string content          = serializedEntity.Data.Results[0].Description;
            var    thumbnail        = serializedEntity.Data.Results[0].Thumbnail;

            var reply = activity.CreateReply();

            HeroCard myCard = new HeroCard
            {
                Title    = name,
                Subtitle = content
            };

            List <CardImage> imageList      = new List <CardImage>();
            CardImage        characterImage = new CardImage(thumbnail.CreatePath("portrait_uncanny"));

            imageList.Add(characterImage);
            myCard.Images = imageList;
            reply.Attachments.Add(myCard.ToAttachment());

            await context.PostAsync(reply);

            context.Wait(MessageReceivedAsync);
        }