2016-08-04 5 views
1

のための電子メールサービスを実装します:どのように私は、Microsoftのボットフレームワークの電子メール機能をテストするためには、私のプロジェクトに次の行を取得しようとしていますマイクロソフトのWebロボット

   List<ChannelAccount> participants = new List<ChannelAccount>(); 
       participants.Add(new ChannelAccount("[email protected]", "Shahin Ansari")); 
       IMessageActivity message = Activity.CreateMessageActivity(); 
       bool isGroup = false; 
       ConversationParameters cpMessage = new ConversationParameters(message.Recipient, isGroup, participants, "Quarter End Discussion"); 
       var ConversationId = connector.Conversations.CreateConversationAsync(cpMessage); 
       //message.From = botChannelAccount; 
       message.From = new ChannelAccount(); 
       message.Conversation = new ConversationAccount(); 

       message.ChannelId = "email"; 

       message.Text = "Hey, what's up everyone?"; 

       message.Locale = "en-Us"; 

       connector.Conversations.SendToConversation((Activity)message); 
       //await connector.Conversations.SendToConversation((Activity)message); 
       var replyMessage = activity.CreateReply("Yo, I heard you Sean.", "en"); 
       connector.Conversations.ReplyToActivityAsync(replyMessage); 

をしかし、私は何のメールを受信しません。

「印刷してください」という声明は、私がトップに置いたときに「あなたがショーンだと聞いたことがある」と言うことを知っています。しかし、それは底にあるときではありません。そのような数行で何かが壊れます。しかし、私はAzureにプッシュしたときにこれをトラブルシューティングする方法を知らないし、ローカルでデバッグすることはうまくコンパイルされていると思われるので、私はそれほど多くは得られません。誰もこれを前にしていますか?

あなたが提案したすべてのアップデートを行い、Azureにプッシュしましたが、電子メールは生成されません。ここに私の更新されたコードがあります:

namespace Bot_Application1 
{ 
    [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) 
      { 
       ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); 
       // calculate something for us to return 
       int length = (activity.Text ?? string.Empty).Length; 

       // return our reply to the user 
       Activity reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters"); 
       await connector.Conversations.ReplyToActivityAsync(reply); 
       var replyMessage = activity.CreateReply("Yo, I heard you Sean.", "en"); 
       await connector.Conversations.ReplyToActivityAsync(replyMessage); 

       // Start of my own code 
       //try { 
       // The code until the line above 
       List<ChannelAccount> participants = new List<ChannelAccount>(); 
       participants.Add(new ChannelAccount("[email protected]", "Shahin Ansari")); 

       IMessageActivity message = Activity.CreateMessageActivity(); 
       bool isGroup = false; 
       ConversationParameters cpMessage = new ConversationParameters(message.Recipient, isGroup, participants, "Quarter End Discussion"); 
       var ConversationId = await connector.Conversations.CreateConversationAsync(cpMessage); 
       message.Recipient = new ChannelAccount("[email protected]", "Shahin Ansari"); 
       //message.From = new ChannelAccount("[email protected]", "Shahin Ansari"); 

       message.From = new ChannelAccount(); 
       //message.From = message.ChannelData; 
       message.Conversation = new ConversationAccount(id: ConversationId.Id); 

       message.ChannelId = "email"; 

       message.Text = "Hey, what's up everyone?"; 

       message.Locale = "en-Us"; 

       connector.Conversations.SendToConversation((Activity)message); 
       //await connector.Conversations.SendToConversation((Activity)message); 

       //} 
       //catch (Exception ex) 
       //{ 
       // Trace.TraceError("Sean's Exception: " + ex.ToString()); 
       // throw; 
       //} 
       //await connector.Conversations.ReplyToActivityAsync(reply); 

      } 
      else 
      { 
       HandleSystemMessage(activity); 
      } 
      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) 
      { 
       // Handle conversation state changes, like members being added and removed 
       // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info 
       // Not available in all channels 
      } 
      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; 

     } 
    } 
} 

答えて

0

主な問題は、メッセージに会話の値を設定する必要があります。また、おそらく非同期機能に待つ必要があります。

 List<ChannelAccount> participants = new List<ChannelAccount>(); 
     participants.Add(new ChannelAccount("[email protected]", "Shahin Ansari")); 
     IMessageActivity message = Activity.CreateMessageActivity(); 
     bool isGroup = false; 
     ConversationParameters cpMessage = new ConversationParameters(message.Recipient, isGroup, participants, "Quarter End Discussion"); 
     var ConversationId = await connector.Conversations.CreateConversationAsync(cpMessage); 
     //message.From = botChannelAccount; 
     message.From = new ChannelAccount(); 
     message.Conversation = new ConversationAccount(); 

     message.ChannelId = "email"; 
 message.Conversation = new ConversationAccount(id: ConversationId.Id); 
 message.Text = "Hey, what's up everyone?"; 

     message.Locale = "en-Us"; 

     connector.Conversations.SendToConversation((Activity)message); 
     //await connector.Conversations.SendToConversation((Activity)message); 
     var replyMessage = activity.CreateReply("Yo, I heard you Sean.", "en"); 
     await connector.Conversations.ReplyToActivityAsync(replyMessage); 
+0

感謝を。それは働いている。いくつかのことがあります。微調整する必要がありますが、電子メールが生成されています。 – maverick

関連する問題