java - 使用java在twilio中获取whatsapp消息的编号和正文
问题描述
我有一个我正在尝试解决的问题。我收到来自 WhatsApp 的消息,我正在尝试使用 Twilio SDK for java 进行回复。
这是我的代码:
package com.boilerplate.controllers;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
@Controller
@Repository
@Transactional
@RequestMapping("/boilerplate")
public class BoilerplateController {
public static final String ACCOUNT_SID = "";
public static final String AUTH_TOKEN = "";
@Autowired
private SessionFactory sessionFactory;
@ResponseBody
@RequestMapping(value = { "/wizard" }, method = RequestMethod.POST)
public String wizardSave(@RequestParam String from,@RequestParam String body) {
// String q1_field = "0";
// String q2_field = "0";
// String q3_field = "0";
// String q4_field = "0";
String undone = "UNDONE";
// String status = "";
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Message message = Message.creator(
new com.twilio.type.PhoneNumber(from),
new com.twilio.type.PhoneNumber("whatsapp:+14155238886"),
"Hello there!")
.create();
return undone;
}
}
出于某种原因,这段代码
@ResponseBody
@RequestMapping(value = { "/wizard" }, method = RequestMethod.POST)
public String wizardSave(@RequestParam String from,@RequestParam String body) {
没有得到我需要的 from 和 body。
我正在使用 spring,并且我使用了注释 @RequestParam
我无法得到 from 和 body。为什么?。
注意:我得到的唯一错误是 Twilio 说我无法连接。
解决方案
这样解决了
@ResponseBody
@RequestMapping(value = { "/wizard" }, method = RequestMethod.POST)
public String wizardSave(@RequestParam("Body") String message,
@RequestParam("From") String from) {
并发送
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Message messagem = Message.creator(
new com.twilio.type.PhoneNumber(from),
new com.twilio.type.PhoneNumber("whatsapp:+14155238886"),
"Sent From one")
.create();
System.out.println(messagem.getSid());
推荐阅读
- terraform - 有没有办法将 terraform 配置为具有可选的第二个 nic 的 VM?
- c++ - 为什么要使用 _tcscpy_s 而不是 _tcscpy?
- sql - 如何减去两个特定行并创建带有答案的自定义列
- python - 我在 python 中使用 postgresql 进行注册编码时遇到了重大问题
- javascript - 我想使用 jsdoc 在我的代码中添加解释
- javascript - 如何在 5 秒后禁用按钮(discord.js)
- javascript - 如何根据日期自动在猫鼬中添加文档
- azure - Azure AD b2c 自定义策略签名/注册错误:-AADB2C:加密密钥必须是 256 位密钥错误
- javascript - 在 JavaScript 中解析和修改一个 html 字符串
- java - ActiveMQ 连接 URL 中的掩码密码