Is there a way I can make BotConnector to _forger_ a user it is connecting with. Meaning, reset it's session.
For example, I would like to use /stop command to completely forget a user, but next time user initiate a chat, the bot will act as this is a first interaction.
I know I could have a flag as session.firstRun as in the examples, but I wonder if there is a cleaner way.
BotConnector supports a native /deleteprofile command. if a user sends this command to the bot, the connector will confirm the delete action with the user and sends a message with the type of DeleteUserData to the bot. The bot should delete all the data related to that user in its storage space and send a reply with the same message type to BotConnector. As a result, next time that the user talks to the bot, he/she will look like a new user.
Shouldn't this work in C#?
var message = msg.CreateReplyMessage(" /deleteprofile");
message.Type = "DeleteUserData";
await context.PostAsync(message);
I've tried inspecting this message and comparing it to the system message sent from the emulator and it seems like there's a lot that doesn't get copied over when creating a reply message from the current message. What are the key items to copy over from the current message to my newly created message to ensure it gets sent as a recognized system message (such as "DeleteUserData")?
Thanks,
R
'/deleteprofile' is a command that is sent by the user to bot and connector impelemnts the logic to map it to the right message type. I am not sure if emulator implements the command handling. Also if you want to reset everything on your bot side, you can easily clear all the data on the incoming message and send it back with empty text as reply. This will reset everything for that user and conversation.
Sure, but shouldn't I be able to send that programmatically as well? The emulator has a "Delete User Data" message which triggers the HandleSystemMessage method in the MessagesController in the examples however I can't seem to trigger it myself in code. The emulator does not, however, handle the /deleteprofile message when sent directly by the user.
@rodzillarr thanks for expanding on this. I too would like to have a programmatic approach for node
/deleteprofile is a command sent by user to initiate the deletion of profile and reset of everything. Bot can easily reset everything programmatically by clearing out the data fields on the message. Below you can see an example of how I modified the code for echo bot to reset everything for that conversation after 2 seconds.
public async Task<Message> Post([FromBody]Message message)
{
Task.Delay(2000).ContinueWith(async (t) =>
{
var client = message.From.ChannelId == "emulator" ? new ConnectorClient(new Uri("http://localhost:9000"), new ConnectorClientCredentials()) : new ConnectorClient();
var clearMsg = message.CreateReplyMessage();
clearMsg.Text = $"Reseting everything for conversation: {message.ConversationId}";
clearMsg.BotUserData = new object { };
clearMsg.BotConversationData = new object { };
clearMsg.BotPerUserInConversationData = new object { };
await client.Messages.SendMessageAsync(clearMsg);
});
return await Conversation.SendAsync(message, () => new EchoDialog());
}
Also we are considering adding a reset helper to dialog context to make it easier to reset a conversation.
In Skype & Slack user can't send command /deleteprofile.
do you think it's worth implementing session.end()
@wiltodelta skype and slack eating / command as their commands. you can put a space in front of command /deleteprofile in slack and skype to make sure that it is delivered to connector.
@mikkhait session.reset() in node code should reset the callstack and begin a new dialog based on passed in dialogId with the user.
Nice! It would be good to document it. Thanks @msft-shahins
@msft-shahins Thanks, it works! But it does not seem normal to add a space before /deleteprofile. Maybe think about the different commands depending on the environment?
I agree. We are thinking about generalizing the system commands accross different channels.
Hello,
How can I have my own custom command to delete profile or reset the session?
If you are using the stock storage you need to set the userbotData or conversationBotdata or peruserincovnersationbotdata to empty object
From: Ahmet Taha Sakar [mailto:[email protected]]
Sent: Monday, May 2, 2016 3:00 PM
To: Microsoft/BotBuilder [email protected]
Subject: Re: [Microsoft/BotBuilder] BotConnector to reset a session (#101)
Hello,
How can I have my own custom command to delete profile or reset the session?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHubhttps://github.com/Microsoft/BotBuilder/issues/101#issuecomment-216378377
/deleteprofile seem to stopped working this morning (using node 0.10.2)
By stopped working, I mean session is not being reset, no prompt to confirm reset.
Did you make sure there's a space before the command? That burned me a couple of times in the past.
tried both ways... looks like it's working on my older bots... hmm
still an issue
I know, I know... but this works for me... :)
bot.use(function (session, next) {
if (session.message.text === '💩') {
session.perUserInConversationData = {};
session.userData = {};
session.conversationData = {};
}
if (!session.userData.firstRun) {
session.userData.firstRun = true;
session.beginDialog('/firstRun');
} else {
next();
}
});
I seems like /deleteprofile stopped working in V3. What's the new mechanism for triggering messages (activities) of type DeleteUserData? Or should I implement my own commands for this?
how do you trigger this in node.js?
bot.send('/deleteprofile') will that do it
@mikkhait how do you trigger that? from the root dialog
@slidenerd This is not supported in V3 anymore. You can implement your own mechanism for this. See this.
we've used /deleteprofile very recently so I'm pretty sure it still works. Note that in some channels it must be preceded by a space
is there any way to access the default bot storage?!
@alokraj68 can you clarify? You want something outside of UserData, ConversationData, and PrivateConversationData?
@brandonh-msft Yup!. I got it from the terms you told! Thanks a lot!
The /deleteprofile command doesn't seem to work in Telegram, even when preceded by a space, line break or other characters.
However, it works fine on channels like Facebook.
i believe " /deleteprofile" works fine just yesterday for slack, but today i've found it doesn't work, watched in debugger and type of activity is just "message" though it migh be "ActivityTypes.DeleteUserData" as i get it. Any info on that? Can be the issue that some other info stuck in serialized context (i played a bit with dialog chains)
FYI, via code, this worked for me:
private async Task _reset(Activity activity)
{
await activity.GetStateClient().BotState
.DeleteStateForUserWithHttpMessagesAsync(activity.ChannelId, activity.From.Id);
var client = new ConnectorClient(new Uri(activity.ServiceUrl));
var clearMsg = activity.CreateReply();
clearMsg.Text = $"Reseting everything for conversation: {activity.Conversation.Id}";
await client.Conversations.SendToConversationAsync(clearMsg);
}
@tomlm would something like this work? context.UserData.SetValue(@"profile",new object{});
Most helpful comment
@wiltodelta skype and slack eating
/command as their commands. you can put a space in front of command/deleteprofilein slack and skype to make sure that it is delivered to connector.@mikkhait
session.reset()in node code should reset the callstack and begin a new dialog based on passed in dialogId with the user.