I use pinput for check registration code by send email code in register. I have problem in integration test in enter registration code, because testing doesn't know correct code.
code
// register email request success test
await registerTest.enterEmail("example#email.com");
await registerTest.onTapContinueButton(true);
expect(loadingOverlay, findsOneWidget);
await tester.pump(const Duration(seconds: 1));
expect(bottomInfoSnackbar, findsOneWidget);
await tester.pump();
// enter verification code
await registerTest.enterVerificationCode("1234");
await tester.pump();
expect(bottomInfoSnackbar, findsOneWidget);
await tester.pumpAndSettle();
Related
I have a xUnit test to quickly check if my API behaves correctly. It's not mocked, just follows some scenarios on flows.
[Fact]
public async Task HappyPath()
{
User = await authHelper.CreateUser();
ContentCreator = await authHelper.CreateUser(isContentCreator: true);
RequestId = await Create();
await User_Should_See_Request_Before_Approval();
await Content_Creator_Should_Not_See_Request_Before_Approval();
await Approve();
await Second_Approve_Should_Fail();
await List();
await Offer();
await Offer();
await Offer();
//await Pay();
// Cleanup
if (shouldCleanup)
{
await Cleanup();
}
}
All these methods are doing API calls with proper generated values.
When I debug the test, it runs normally and I can get the green tick.
However, when I run the test (CTRL + R, T), even as a single, it keeps running indefinitely. While it runs I can observe all endpoints are called, and resources cleaned up. But the test just keeps running.
I'm not observing anything in the output (was hunting for exceptions) and on Visual Studio 2022 17.4.4.
I have developed a bot which sends Proactive messages to user
I also cretaed bots which trigger skills.
I was trying to write something where a skills bot/Dialog would be able to send proactive message received via webhooks to the user and continue with the existing Skill dialog.
I am not able to quite understand that. If anyone could help me there.
I used the sample from here to create a simple Skill bot which saves the ConversationReference of the current Activity and calls a service in OnMessageActivityReceived()
// Save ConversationReference
var conversationReference = activity.GetConversationReference();
_conversationReferences.AddOrUpdate(conversationReference.User.Id, conversationReference, (key, newValue) => conversationReference);
// Calling external service
HttpResponseMessage responsemMsg = await client.PostAsync(RequestURI, stringContent);
if (responsemMsg.IsSuccessStatusCode)
{
var apiResponse = await responsemMsg.Content.ReadAsStringAsync();
//Post the API response to bot again
await turnContext.SendActivityAsync(MessageFactory.Text($"Message Sent {turnContext.Activity.Text}"), cancellationToken);
}
The called service eventually emits an event which calls an action in the NotifyController in my Skills Bot. It tries to grab the ConverstaionReference and send the activity using the TurnContext.
//I am using the Skill Bot Id for _appId parameter
await ((BotAdapter)_adapter).ContinueConversationAsync(_appId, conversationReference, async (context, token) =>
{
await context.SendActivityAsync(proMsg.eventName);
await context.SendActivityAsync(proMsg.context.ToString());
}, new System.Threading.CancellationToken());
This SendActivity fails and OnTurnError from the Skill Bot handles the exception.
I am not sure where excatly I am going wrong. I am new to the Bot framework learning.
My issue got resolved by using the ContinueConversation() overload with ClaimsIdentity and setting the right claims for audience, appid etc. It was basically authentication issue.
public virtual Task ContinueConversationAsync(ClaimsIdentity claimsIdentity, ConversationReference reference, string audience, BotCallbackHandler callback, CancellationToken cancellationToken);
This is how I created the ClaimsIdentity:
System.Collections.Generic.List<Claim> lclaim = new System.Collections.Generic.List<Claim>
{
new Claim(AuthenticationConstants.VersionClaim, "2.0"),
new Claim(AuthenticationConstants.AudienceClaim, <SkillBotId>),
new Claim(AuthenticationConstants.AppIdClaim, <SkillBotId>),
new Claim(AuthenticationConstants.AuthorizedParty, <SkillBotId>),
};
ClaimsIdentity ci = new ClaimsIdentity(lclaim);
async Task BotCallBack(ITurnContext turnContext, CancellationToken token)
{
<code to send activity back to parent bot>
}
await ((BotAdapter)this.botFrameworkHttpAdapter).ContinueConversationAsync(
ci,
conversationData.ConversationReference,
<ParentBotId>,
callback: BotCallBack,
default).ConfigureAwait(false);
I was able to convert my EchoBot to interact with QnAMaker as per instructions here on my local development system but when I publish the same using kudu repo (tried using Azure DevOps service Ci/CD pipeline but it does not work [in preview] because after deployment the bot just hangs on portal and never able to test it on web chat.. so gave up and used recommended kudu repo), I do not get the correct answer to my response. For every question I send, it is unable to detect the QnAMaker service. And I am returning error message from the code that says no QnaMaker answer was found.
How do I troubleshoot to identify the cause of this?
My bot file seems to be working fine locally and I am able to get the answer from QnAMaker locally but not after publishing the code to my Web App Bot in Azure.
I feel like Botframework V4 (using .net) is not very straight forward and the instruction on the portal (document) is still kind of evolving or sometime incomprehensible.
Here is the snapshot from my emulator while testing the chat locally:
And here is the snapshot of production endpoint (using the same questions on portal) with my error msg from OnTurnAsync function:
My .bot has all the services defined and local bot is working fine.
This is the code in my ChatBot class:
public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
// Handle Message activity type, which is the main activity type for shown within a conversational interface
// Message activities may contain text, speech, interactive cards, and binary or unknown attachments.
// see https://aka.ms/about-bot-activity-message to learn more about the message and other activity types
if (turnContext.Activity.Type == ActivityTypes.Message)
{
// Get the conversation state from the turn context.
var state = await _accessors.CounterState.GetAsync(turnContext, () => new CounterState());
// Bump the turn count for this conversation.
state.TurnCount++;
// Set the property using the accessor.
await _accessors.CounterState.SetAsync(turnContext, state);
// Save the new turn count into the conversation state.
await _accessors.ConversationState.SaveChangesAsync(turnContext);
// Echo back to the user whatever they typed.
//var responseMessage = $"Turn {state.TurnCount}: You sent '{turnContext.Activity.Text}'\n";
//await turnContext.SendActivityAsync(responseMessage);
// QnAService
foreach(var qnaService in _qnaServices)
{
var response = await qnaService.GetAnswersAsync(turnContext);
if (response != null && response.Length > 0)
{
await turnContext.SendActivityAsync(
response[0].Answer,
cancellationToken: cancellationToken);
return;
}
}
var msg = "No QnA Maker answers were found. Something went wrong...!!";
await turnContext.SendActivityAsync(msg, cancellationToken: cancellationToken);
}
else
{
await turnContext.SendActivityAsync($"{turnContext.Activity.Type} event detected");
}
}
I have a bot in Bot framework. Once user responds to the bot and bot is processing it, I want to show the typing indicator to the user in the meanwhile.
It is possible in Nodejs here - https://learn.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-send-typing-indicator
But how can I implement it in C#?
You have to send an activity of type Typing.
You can do it like that:
// Send "typing" information
Activity reply = activity.CreateReply();
reply.Type = ActivityTypes.Typing;
reply.Text = null;
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
await connector.Conversations.ReplyToActivityAsync(reply);
You can also create the message using context.MakeMessage if you need to instantly respond in MessageReceivedAsync of a dialog.
var typingMsg = context.MakeMessage();
typingMsg.Type = ActivityTypes.Typing;
typingMsg.Text = null;
await context.PostAsync(typingMsg);
The typing indicator is replaced by the next message sent (at least in the Bot Framework emulator). This doesn't seem to work in Slack.
Here's another approach to send a typing indicator with a bot framework in C#, JavaScript, or Python.
Try use this:
var reply = activity.CreateReply();
reply.Text = null;
reply.Type = ActivityTypes.Typing;
await context.PostAsync(reply);
For showing typing indicator while bot is processing just add in OnTurnAsync function before await base.OnTurnAsync(turnContext, cancellationToken); :
await turnContext.SendActivityAsync(new Activity { Type = ActivityTypes.Typing }, cancellationToken);
If V4, following lines of code can help. Keep this code at such a place so that it gets executed everytime during the dialogue flow.
IMessageActivity reply1 = innerDc.Context.Activity.CreateReply();
reply1.Type = ActivityTypes.Typing;
reply1.Text = null;
await innerDc.Context.SendActivityAsync( reply1, cancellationToken: cancellationToken);
await Task.Delay(1000);
I have a couple of questions about the example that shows how to start a proactive dialog:
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, activity))
{
var botData = scope.Resolve<IBotData>();
await botData.LoadAsync(token);
var task = scope.Resolve<IDialogTask>();
var interruption = dialog.Void<T, IMessageActivity>();
task.Call(interruption, null);
await task.PollAsync(token);
await botData.FlushAsync(token);
}
What is the point of calling dialog.Void?
How can I use a ResumeAfter? If i add a ResumeAfter handler and await the result i get an error indicating it was expecting Call and got Poll
Is this code supposed to block until the dialog is complete? Because it does not
How can I push a proactive dialog and await its result?