【发布时间】:2020-06-26 07:35:24
【问题描述】:
我创建了一个基本的 spring boot 应用程序(从 heroku 开始的 java-getting-started),添加了一个端点,我已将其配置为我的电报机器人上的 webhook。
但是看起来端点对 GET 请求做出反应,我希望它是一个 POST,因此有一个要解析的主体
@Controller
@SpringBootApplication
public class Main {
@RequestMapping(value = "/testendpoint", method = RequestMethod.GET)
public String testendpoint() {
// send a response to the bot, this part works fine
}
我应该如何阅读电报机器人发送的内容?它应该是包含 message > chat > id 和 message > text 等字段的 json,PHP 中的等效项适用于此:
$update = json_decode(file_get_contents("php://input"), TRUE)
$chatId = $update["message"]["chat"]["id"];
$message = $update["message"]["text"];
来自https://nordicapis.com/how-to-build-your-first-telegram-bot-using-php-in-under-30-minutes/
所以我有点困惑我的控制器应该如何处理内容..
【问题讨论】:
-
您是否尝试过更改第一个代码中的
RequestMethod.GET? -
是的,我也有它的双端点和 POST,但答案是 GET
标签: java php spring spring-boot telegram