- 场景
如果企业中有了自己的语音和短信渠道,Dataphin支持连接企业自有的语音和短信渠道,在Dataphin中应该如何配置参数?
- 解决方案及功能
首先我们需要了解一些通信API的基本请求方式,我们以Twilio API为例,简要介绍一下sdk中的请求参数如何在Dataphin中进行配置
①ACCOUNT_SID和AUTH_TOKEN是调用Twilio API所必须的账号SID和认证令牌,我们可以放在headers里面
private static final String ACCOUNT_SID = "your_account_sid"; private static final String AUTH_TOKEN = "your_auth_token"; private static final String TWILIO_PHONE_NUMBER = "+12345678901"; // Twilio电话号码 private static final String RECIPIENT_PHONE_NUMBER = "+12345678901"; // 接收者电话号码 private static final String TWIML_URL = "http://yourserver.com/twiml.xml"; // TwiML URL public static void main(String[] args) throws IOException { OkHttpClient client = new OkHttpClient(); // Prepare the request body RequestBody requestBody = new FormBody.Builder() .add("To", RECIPIENT_PHONE_NUMBER) .add("From", TWILIO_PHONE_NUMBER) .add("Url", TWIML_URL) .build(); // Prepare the request with headers and body Request request = new Request.Builder() .url("https://api.twilio.com/2010-04-01/Accounts/" + ACCOUNT_SID + "/Calls.json") .post(requestBody) .addHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString((ACCOUNT_SID + ":" + AUTH_TOKEN).getBytes())) .build(); // Execute the request try (Response response = client.newCall(request).execute()) { if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); System.out.println("Call initiated successfully."); } }
点击切换按钮可以切换为输入框或者下拉框
②body中的参数可以同样配置,其中的${receiver_message}在【告警中心-消息模板】中进行配置,不同任务可以配置不同的消息模板
③${receiver_message}即为消息模板中的内容,中间的参数会根据Dataphin中的实际情况进行传参,并发送给Twilio API中的TWIML_URL,从而完成请求
④填写完毕后可以点击下方的发送测试消息进行测试