I was trying to add a functionality to take input-attachments from the user, basically trying to merge the handling-attachments bot sample from bot framework and my custom waterfall dialog .
But how do you access iturncontext functions in the waterfall dialog? . Below is a explanation of my code.
One of my waterfall step :
private async Task<DialogTurnResult> DescStepAsync2(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
stepContext.Values["Title"] = (string)stepContext.Result;
await stepContext.Context.SendActivityAsync(MessageFactory.Text("upload a image"), cancellationToken);
var activity = stepContext.Context.Activity;
if (activity.Attachments != null && activity.Attachments.Any())
{
Activity reply = (Activity)HandleIncomingAttachment(stepContext.Context.Activity);
return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = reply }, cancellationToken);
}
else
{
var reply = MessageFactory.Text("else image condition thrown");
// reply.Attachments.Add(Cards.GetHeroCard().ToAttachment());
return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = reply }, cancellationToken);
}
}
Here is the HandleIncomingAttachment function which i borrowed from bot builder samples linked above .
private static IMessageActivity HandleIncomingAttachment(IMessageActivity activity)
{
string replyText = string.Empty;
foreach (var file in activity.Attachments)
{
// Determine where the file is hosted.
var remoteFileUrl = file.ContentUrl;
// Save the attachment to the system temp directory.
var localFileName = Path.Combine(Path.GetTempPath(), file.Name);
// Download the actual attachment
using (var webClient = new WebClient())
{
webClient.DownloadFile(remoteFileUrl, localFileName);
}
replyText += $"Attachment \"{file.Name}\"" +
$" has been received and saved to \"{localFileName}\"\r\n";
}
return MessageFactory.Text(replyText);
}
Here is the transcript of the conversation:

EDIT: i have edited my code to this , it still doesnt wait for me to upload a attachment .just finishes the step .
private async Task<DialogTurnResult> DescStepAsync2(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
stepContext.Values["Desc"] = (string)stepContext.Result;
var reply = (Activity)ProcessInput(stepContext.Context);
return await stepContext.PromptAsync(nameof(AttachmentPrompt), new PromptOptions { Prompt = reply }, cancellationToken);
}
process input function :
private static IMessageActivity ProcessInput(ITurnContext turnContext)
{
var activity = turnContext.Activity;
IMessageActivity reply = null;
if (activity.Attachments != null && activity.Attachments.Any())
{
// We know the user is sending an attachment as there is at least one item .
// in the Attachments list.
reply = HandleIncomingAttachment(activity);
}
else
{
reply = MessageFactory.Text("No attachement detected ");
// Send at attachment to the user.
}
return reply;
}