Aparna
Aparna

Reputation: 465

How to get current context in Microsoft Bot framework

I am building a form using FormDialog to which I am passing a BuildFormDelegate parameter (a static method). In this method, I need the context to acquire user data.

The user data is stored as part of context written using an extension:

public static async Task<string> GetAccessToken(this IBotContext context, string resourceId)

I call the form context as follows:

var calendarform = new FormDialog<CalendarInput>(new CalendarInput(), MakeCalendarForm, FormOptions.PromptInStart, result);
context.Call<CalendarInput>(calendarform, CalendarFormComplete);

I need to call the GetAccessToken method in the MakeCalendarForm (which does not take any argument). How can I achieve this?

Upvotes: 1

Views: 1283

Answers (1)

Ezequiel Jadib
Ezequiel Jadib

Reputation: 14787

You can call the GetAccessToken before calling the form and pass the resulting token as parameter to the CalendarInput state your passing to the FormDialog you are creating. Something like

var token = await context.GetAccessToken();
var calendarform = new FormDialog<CalendarInput>(new CalendarInput(token), MakeCalendarForm, FormOptions.PromptInStart, result);

However, it sounds strange that you need the token in context of the Form. What are you trying to do?

Upvotes: 2

Related Questions