I'm working on a bot for Microsoft Teams. I am using the custom bot feature. I got the bot working as a sideloaded package, but due to the constraints of my network, I need to keep the bot internal and use the custom bot feature. I am currently testing it by using ngrok to tunnel to my localhost.
I am now running into an issue when I try to create my reply. Whenever I call this:
var reply = activity.CreateReply(message.ReadToEnd());
I get a NullReferenceException saying that the "Object reference not set to an instance of an object". message is an open .txt file. I get this error every time I call activity.CreateReply(). The part that I don't understand is that everything works as intended in the Bot Framework Emulator and when the bot is a sideloaded package, but not when the bot is a custom bot.
Here's my full Post method:
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
if (activity.Type == ActivityTypes.Message)
{
// Commands:
// Retrieve TFS Work Item(s)
if (new Regex(@"\but\s?\d{5}\b").IsMatch(activity.Text.ToLower()))
{
var reply = new RetrieveWorkItem();
await connector.Conversations.ReplyToActivityAsync(reply.Response(activity));
}
// Help
else if (activity.Text.ToLower().Contains("help"))
{
var message = File.OpenText($"{System.AppDomain.CurrentDomain.BaseDirectory}/Messages/HelpMessage.txt");
var reply = activity.CreateReply(message.ReadToEnd());
await connector.Conversations.ReplyToActivityAsync(reply);
}
// Not Recognized
else
{
var reply = activity.CreateReply("Command not recognized. Type \"@Keller Bot Help\" for a list of commands.");
await connector.Conversations.ReplyToActivityAsync(reply);
}
}
else
{
HandleSystemMessage(activity, connector);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
Here's the full error and StackTrace sent by the bot: https://pastebin.com/ZSrjrA9z
reply
object ? – Bob Swager