无法发送重试,但邮件已发送

时间:2017-04-12 23:06:37

标签: botframework

在机器人网络聊天中,当我输入消息时,机器人说"发送"首先,然后更改为"无法发送,重试"。但邮件已发送,我收到了回复。我怎么能避免这个?我是否需要增加消息超时?如果是这样,我需要在哪里设置它?

enter image description here

这是代码段。我正在使用C#SDK,我在MessageReceivedASync方法中编码

namespace Bot_Application1.Dialogs
{
    public class HRBotDialog : IDialog<object>
    {
        public static string dialogcontext = "";
        public async Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceivedAsync);
        }

        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
        {
            // Get the text passed
            var message = await argument;
            string typedText = message.Text.ToLower();
            string answer = "My Answer";
            if ((typedText == "hi") || (typedText == "hello"))
            {
                answer = message.Text;

            }
            else if ((typedText == "how many personal days do i have left") || (typedText.Contains("personal days")))
            {
                answer = "Looks like you have 2 remaining for this year";
            }

我在这里添加控制器代码

//[BotAuthentication]
public class MessagesController : ApiController
{
    /// <summary>
    /// POST: api/Messages
    /// Receive a message from a user and reply to it
    /// </summary>
    public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
    {
        if (activity.Type == ActivityTypes.Message)
        {
            await Conversation.SendAsync(activity, () => new HRBotDialog());
        }
        else
        {
            ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
            var reply = HandleSystemMessage(activity);
            if (reply != null)
                await connector.Conversations.ReplyToActivityAsync(reply);
        }
        var response = Request.CreateResponse(HttpStatusCode.OK);
        return response;
    }

    private Activity HandleSystemMessage(Activity message)
    {

        if (message.Type == ActivityTypes.DeleteUserData)
        {
            // Implement user deletion here
            // If we handle user deletion, return a real message
        }
        else if (message.Type == ActivityTypes.ConversationUpdate)
        {
            string replyMessage = string.Empty;
            if (message.MembersAdded.Any(o => o.Id == message.Recipient.Id))
            {
                replyMessage += $"How can I help you? \n";
                return message.CreateReply(replyMessage);
            }
        }
        else if (message.Type == ActivityTypes.ContactRelationUpdate)
        {
            // Handle add/remove from contact lists
            // Activity.From + Activity.Action represent what happened
        }
        else if (message.Type == ActivityTypes.Typing)
        {
            // Handle knowing tha the user is typing
        }
        else if (message.Type == ActivityTypes.Ping)
        {
        }

        return null;
    }
}

1 个答案:

答案 0 :(得分:0)

请尝试将Serializable属性添加到HRBotDialog中,如下所示:

[Serializable]
public class HRBotDialog : IDialog<object>
{
//...code...
}