示例#1
0
        private async Task <DialogTurnResult> GetStreamersStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (stepContext.Result != null && stepContext.Result is string)
            {
                var result = (string)stepContext.Result;
                if (result.TryParseJson(out JObject tagsJson))
                {
                    if (tagsJson.ContainsKey("tags"))
                    {
                        var typing = stepContext.Context.Activity.CreateReply();
                        typing.Type = ActivityTypes.Typing;
                        typing.Text = null;

                        var tagsAsString = tagsJson["tags"].ToString();

                        try
                        {
                            var channels = await _client.GetChannelsHavingTags(tagsAsString);

                            if (channels.Any())
                            {
                                var reply = stepContext.Context.Activity.CreateReply();
                                reply.Attachments = new List <Attachment>
                                {
                                    ChannelListCard.Create(channels, "Channels of Interest"),
                                };
                                await stepContext.Context.SendActivityAsync(reply, cancellationToken);
                            }
                            else
                            {
                                await stepContext.Context.SendActivityAsync(
                                    MessageFactory.Text("Sorry, I can't find any live coding streamers that match your interests."));
                            }
                        }
                        catch (Exception)
                        {
                            await stepContext.Context.SendActivityAsync(
                                MessageFactory.Text($"I'm sorry, but I am having problems talking to the Dev Streams database."));
                        }
                    }

                    return(await stepContext.EndDialogAsync());
                }
            }

            return(await stepContext.ReplaceDialogAsync(Constants.DiscoverIntent, cancellationToken));
        }
示例#2
0
        private async Task <DialogTurnResult> GetLiveStreamsStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var typing = stepContext.Context.Activity.CreateReply();

            typing.Type = ActivityTypes.Typing;
            typing.Text = null;

            await stepContext.Context.SendActivityAsync(typing);

            try
            {
                var channels = await _client.GetLiveChannels();

                if (channels != null && channels.Count > 0)
                {
                    var reply = stepContext.Context.Activity.CreateReply();
                    reply.Attachments = new List <Attachment> {
                        ChannelListCard.Create(channels, "Currently Live")
                    };
                    await stepContext.Context.SendActivityAsync(reply, cancellationToken);
                }
                else
                {
                    await stepContext.Context.SendActivityAsync(
                        MessageFactory.Text($"There are no DevStreams live coding streams currently broadcasting."));
                }
            }
            catch (Exception ex)
            {
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text($"I'm sorry, but I am having problems talking to the Dev Streams database."));

                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text($"{ex.Message}"));
            }

            return(await stepContext.EndDialogAsync(cancellationToken));
        }