简体   繁体   中英

error while testing the Echo Chat Bot on Azure

I'm following https://towardsdatascience.com/creating-a-serverless-python-chatbot-api-in-microsoft-azure-from-scratch-in-9-easy-steps-2f1913fc9581 in creating a python chatbot, and my source code is as below, however when I try to run it, I'm getting an error. According to repositories that error is the adapter's on_error handler receives any exceptions thrown by bot's turn logic. If there is an exception thrown, the handler deletes the conversation state for the current conversation to prevent the bot from getting stuck in an error-loop caused by being in a bad state. any expert can help with this?

       using System.Collections.Generic;                 
       using System.Threading;           
       using System.Threading.Tasks;          
       using Microsoft.Bot.Builder;          
       using Microsoft.Bot.Schema;          
       using System.Net;       
       using System;         
       using System.Net.Http;          
       using System.Text;  // for class Encoding         
       using System.IO;               
       using Newtonsoft.Json;                 
       using Newtonsoft.Json.Serialization;     
            

       namespace Microsoft.BotBuilderSamples.Bots
       {
           public class EchoBot : ActivityHandler
           {
               public class FlaskRequestModel
               {
                   [JsonProperty("text")]
                   public string Text {get; set;}            
        
               }

               protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity>                       turnContext, CancellationToken cancellationToken)
               {           
                   var replyText = $"{turnContext.Activity.Text}";
                   //if (!replyText.ToLower().Contains("Hey Bot")){  # Optional bit of code that only sends the sends the message to the back end if it contains a particular keyword
                   //    return;
                   //}
                   var replyTextModel = new FlaskRequestModel()
                   {
                       Text = replyText 
                   };

                   var jsonObject = JsonConvert.SerializeObject(replyTextModel);
    
                   var request = new HttpRequestMessage()
                   {

                       Content = new StringContent(jsonObject, Encoding.UTF8, "application/json"),
                       Method = HttpMethod.Post,
                       RequestUri = new Uri("yudao.azurewebsites.net"),   //  <- Replace the URL with the the URL for your function app
                   };            
    
                   var httpClient = new HttpClient();
                   // httpClient.DefaultRequestHeaders.Add("API-Key","your API-key");  <- required if your HTTP trigger authorization was set to something other than Anonymous
                   var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead);      
    
                   if (response.IsSuccessStatusCode)
                   {
                       var responseString = await response.Content.ReadAsStringAsync();
                       await turnContext.SendActivityAsync(MessageFactory.Text(responseString, responseString), cancellationToken);
                   }
                   else
                   {
                       await turnContext.SendActivityAsync(MessageFactory.Text("failure", "failure"), cancellationToken);
                       var responseString = await response.Content.ReadAsStringAsync();
                       await turnContext.SendActivityAsync(MessageFactory.Text(responseString, responseString), cancellationToken);   
                   }
    
               }
           }    
       }

try this using regex:

A2 = "12 15|||Pform|||their|||REQUIRED|||-NONE-|||0"
intval=[val for val in A2.split('|||') if bool(re.search(pattern='\d+', string=val))]

Output:

['12 15', '0']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM