我正在使用Telegeram.bot在.net上开发简单的电报机器人 我将我的机器人(管理员)添加到公共频道,我希望从频道重新发送消息并重新发送给机器人用户
但我有问题,这是我的代码
#region Properties
private Api bot;
string botToken = "Bot Token";
#endregion
#region Constructor
/// <summary>
/// Basic constructor for the api controller
/// </summary>
public WebhookController()
{
bot = new Api(botToken);
}
#endregion
public async Task<IHttpActionResult> Post(Update update)
{
var text = update.Message.Text;
var chatType = update.Message.Chat.Type;
if (chatType == ChatType.Channel)
{
// Send Text message to users that previusly we gathered their telegram id and saved them in our DB
// ******Problem is here******
}
else if (chatType == ChatType.Private)
{
if (text != null && text.Contains("/start") || text.Contains("start"))
{
await bot.SendTextMessage(chatId: update.Message.Chat.Id, text: "START");
}
}
else
{
await bot.SendTextMessage(chatId: update.Message.Chat.Id, text: "ERROR!!!");
}
return Ok();
}
public string Get()
{
return "Yes Its Work";
}
但我收到500内部服务器错误
"Message": "An error has occurred.",
"ExceptionMessage": "Object reference not set to an instance of an object.",
"ExceptionType": "System.NullReferenceException",
"StackTrace": " at CodeBlock.Bot.Engine.Controllers.webhookController.<Post>d__11.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.AuthenticationFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"