Microsoft Bot working on both emulator and web chat but not Skype
I was working on my bot yesterday, constantly testing it through skype and everything worked perfectly. I then change something completely innocuous and boom, nothing. I rolled back to a previous version that I know for a fact is working on another channel that we're running and nothing. Both webchat and the emulator works. For a while the messages were getting into the message controller up until the point where I send the activity to the root dialog but it never seems to instantiate root dialog. I've tried creating new publish profiles on visual studio, deleting the bot from my Skype contacts and starting again. I've restarted the web app on Azure, updated my packages as much as I can without half my code become useless to the new packages. I was also hoping that maybe if I left it for a few hours skype might decide to start working with me again but no dice.
It doesn't seem to be an authentication issue as it works perfectly on the webchat. As I said, it seemed to stop working when I changed something seemingly very innocuous that has nothing to do with the bot start up or message controller.
Here is my message controller
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Threading; using System.Threading.Tasks; using System.Web.Http; using System.Diagnostics; using Microsoft.Bot.Builder.Dialogs; using Microsoft.Bot.Connector; using NetHope.Dialogs; using NetHope.ProactiveMessage; using NetHope.Speech; using NetHope.TrackConversation;
namespace NetHope.Controllers { [BotAuthentication] public class MessagesController : ApiController { public static Dictionary<string, ConversationThread> userConversations = new Dictionary<string, ConversationThread>(); // This stores messages in a local stack, not a DB
// This is where each new connection comes in, whether its a message or a connection
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
using (ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl), new MicrosoftAppCredentials()))
{
//<update_database>
try
{
await SaveConversationData.SaveConversationAsync(activity.From.Id, activity.From.Name, // feature to update the latest interaction from a user
activity.Recipient.Id, activity.Recipient.Name, activity.ServiceUrl,
activity.ChannelId, activity.Conversation.Id);
}
catch (Exception e)
{
await connector.Conversations.ReplyToActivityAsync(activity.CreateReply(e.ToString())); // Print error
}
//</update_database>
await connector.Conversations.ReplyToActivityAsync(activity.CreateReply(activity.TextFormat));
//if it is a message sent by the user it is sent to root here
if (activity.Type == ActivityTypes.Message)
{
System.Diagnostics.Debug.WriteLine("In Message Activity is Message");
//<add_id_to_dictionary> add new conversation IDs to the dictionary
string conversationId = activity.Conversation.Id;
if (!userConversations.ContainsKey(conversationId))
{
userConversations[conversationId] = new ConversationThread(conversationId);
System.Diagnostics.Debug.WriteLine("Adding new coversation keys to dicts");
}
//<add_id_to_dictionary>
//<audio_to_text> if audio clip sent, extract it and then parse it as text
var audioAttachment = activity.Attachments?.FirstOrDefault(a => a.ContentType.Equals("audio/wav") || a.ContentType.Equals("audio/x-m4a") || a.ContentType.Equals("audio") || a.ContentType.Equals("audio/mp4") || a.ContentType.Equals("audio/mp4"));
if (audioAttachment != null)
{
try
{
string responseFromAPI = await SpeechToTextAuth.DealWithAttachment(audioAttachment, connector, conversationId); // get the text from attachment
await connector.Conversations.ReplyToActivityAsync(activity.CreateReply(responseFromAPI)); // print the text
activity.Text = responseFromAPI; //update the user text input from null to the audio text
}
catch (Exception e)
{
await connector.Conversations.ReplyToActivityAsync(activity.CreateReply(e.ToString())); // print the error
}
userConversations[conversationId].UserMessage("AUDIO"); // if the clip was audio we save audio to the conversation stack
//TODO update the conversation stack to store activities not strings, would allow for the replaying of audioclips
//</audio_to_text>
}
else
{
userConversations[conversationId].UserMessage(activity.Text); // if the input was just text, we add that text to the conversation stack
}
await Conversation.SendAsync(activity, () => new RootDialog()); // pass the typed text (or the parsed text) to the main dialog
System.Diagnostics.Debug.WriteLine("Message been sent to root dialog");
}
//if it is not a message it is sent to the message handlers here
else
{
await HandleSystemMessage(activity); // input is not the type message
}
return Request.CreateResponse(HttpStatusCode.OK);
}
}
//if the system message isnt a message we handle it here
private async Task HandleSystemMessage(Activity message)
{
if (message.Type == ActivityTypes.DeleteUserData) // not implemented
{
}
//if a new user adds the bot as a contact we say hello here
else if (message.Type == ActivityTypes.ConversationUpdate || message.Type == ActivityTypes.ContactRelationUpdate)
{
System.Diagnostics.Debug.WriteLine("In ConversationUpdate/Contact RelaitonUpdate", message.Type);
using (ConnectorClient client = new ConnectorClient(new Uri(message.ServiceUrl), new MicrosoftAppCredentials()))
if (message.MembersAdded.Any(o => o.Id == message.Recipient.Id))
{
await Conversation.SendAsync(message, () => new Dialogs.WelcomeDialog());
}
}
else if (message.Type == ActivityTypes.ContactRelationUpdate) // not implemented
{
// Handle add/remove from contact lists
// Activity.From + Activity.Action represent what happened
}
else if (message.Type == ActivityTypes.Typing) // not implemented
{
// Handle knowing tha the user is typing
}
else if (message.Type == ActivityTypes.Ping) // not implemented
{
}
}
}
}
Before it used to at least get to the Conversation.SendAsync to root dialog but now it doesn't seem to enter the message controller at all.
Also, I'm getting warning in Azure for the app service telling me that invalid XML was detected in case that is relevant, although I think that warning has always been there and it was working fin before
If any more code is needed let me know
I think that my email account was blocked because I was sending too many messages, I started a new skype account and it worked