[.Net SDK, SMS Twilio] messages not being delivered, error 30008
System Information (Required)
- C#*
- Bot Builder 3.5.5*
- *Development environment - On prem windows server 2016
Issue Description
I have simple code that is using the IDialogContext.PostAsync method to communicate back to the end user. In some instances sms cannot be delivered. My Twilio usage logs show error 30008 (Unknown Error), the dev bot framework port shows a corresponding "There was an error sending this message to your bot: HTTP status code InternalServerError" in the channel issues list.
Example Code
-
I am proactively starting a conversation via connector client: ` var serviceUrl = GetServiceUrlByChannelId(channel); MicrosoftAppCredentials.TrustServiceUrl(serviceUrl, DateTime.Now.AddDays(7)); //todo change magic number var account = new MicrosoftAppCredentials(_botCreds.BotId, _botCreds.BotPassword);
_connector = new ConnectorClient(new Uri(serviceUrl), account);
var botAccount = new ChannelAccount { Id = bot.Id, Name = bot.Name }; var toAccount = new ChannelAccount { Id = recipient.Id, Name = recipient.Name };
if (!MicrosoftAppCredentials.IsTrustedServiceUrl(serviceUrl)) { throw new Exception("Cannot create conversation! Service URL is not trusted!"); }
var conversationResponse = _connector.Conversations.CreateDirectConversation(botAccount, toAccount); return conversationResponse.Id;`
-
Here I am constructing a message to be sent via the connector client I created in step 1.
convoMessage.Text = message.Message;
convoMessage.From = new ChannelAccount { Id = message.BotUser.Id, Name = message.BotUser.Name };
convoMessage.Recipient = new ChannelAccount { Id = message.Recipient.Id, Name = message.Recipient.Name};
convoMessage.Conversation = new ConversationAccount(id: conversationUid);
convoMessage.Locale = "en-Us";
convoMessage.ChannelId = message.ChannelId.ToString();
convoMessage.ServiceUrl = GetServiceUrlByChannelId(message.ChannelId);
var response = await _connector.Conversations.SendToConversationAsync((Activity)convoMessage);
return response.Id;
-
The outbound message is sent successfully to the end user. Now the end user responds with some text back.
-
As my conversation is in progress messages inconsistently fail to send.
My expected behavior is if my messages fail delivery I would like my bot to be informed in some way. Am I missing something in documentation or usage of the connector client? I've attached my code to look at more closely. You have a view on how I'm writing my dialogs, but you will not be able to run and build because I cannot share all of my internal code.
I've posted in stack overflow as well. http://stackoverflow.com/questions/43770990/bot-dialog-error-handling
I also get the following error in the sms channel (portal) and does not get thrown in the bot app: "SMS undelivered. Unknown error. Media may have exceeded mobile operator size limit."
@arthurtina724 is this issue still happening? have you tried the newest SDK version 3.8.1 at the time of this post?
@JasonSowers I'm on bot builder 3.5.9 and have not been able to replicate the issue. My only concern is there are multiple ways to reply/post messages back to an end user.
- IDialogContext.PostAsync
- ConnectorClient.Conversations.SendToConversationAsync
These are the 2 methods I am using in my bot. Is there a delegate or way of handling channel transport errors/failures? I don't want to simply close this because I cannot replicate. I would like to know the best practice on handling these type of situations. Does version 3.8.1 offer something new for this ? Thanks.
@arthurtina724 we will look into this further and let you know what we find.
@arthurtina724 are you still experiencing the issue after upgrading to BotBuilder v3.8.1?
@nwhitmont I have not updated to v3.8.1 yet. I'm still on 3.5.9. My question above was geared towards the error handling when using the connectorclient or IDialogContext.PostAsync. Is it as simple as wrapping a try /catch around each of those calls or am I missing something else in the sdk that allows me to handle any type of transport error. In the meantime I will upgrade my bot to 3.8.1 and report any issues.
note* I did replicate an issue today where a message appeared to be delivered correctly via my bot. I did not see any errors posted in the botframework channel dashboard nor did an exception get thrown in my bot application. My IActivityLogger instance logged the activity correctly too. When I checked my twilio logs it does not show as even attempted. So I'm not sure what happened. The conversationId is "+13108455728" on channel sms. Again.. this was using version 3.5.9 of the sdk.
@JasonSowers try/catch of a generic exception type around context.postasync("some message") will do it? I have recently upgraded to the latest bot builder version 3.9.0 and I was still able to replicate the issue I've stated above. Any other insight you would like to provide? ConversationId is the same as I've stated above. Can you re-open this issue?
Sure, no problem
Ping. I am seeing this issue also when I attempt to do SMS forwarding in Twilio. The error logs and it has lots of barfed text with UTCs, I assume IDs, and tons of personal sounding strings. It actually burned up all the money in my Twilio account in a few minutes.........
Can you please let us know if the issue still persists?
Two issues here - we should look into reliability of SMS channel - @craigjensen can you please comment on Twilio service availability and known issues?
As far as bot code being able to handle channel failure, wrapping the postAsync with try..catch is the best solution.
Looks like Twilio was having some issues earlier today: https://status.twilio.com/incidents/w954m468r0gw
A couple ways to catch and log exceptions in the .net sdk are explained here: https://github.com/Microsoft/BotBuilder/issues/4603#issuecomment-389297599 (Override PostUnhandledExceptionToUser and/or provide a custom LogIfExceptionDialog)
Closing this Twilio issue since it appears to be transient.