如何修复404“请求的资源/2010-04-01/Accounts//SMS/Messages.json”在芭蕾舞女演员的Twilio-Connector中找不到错误

时间:2019-01-08 08:50:19

标签: twilio-api ballerina

我正在使用芭蕾舞演员创建客户注册休息服务,与此相关的用例是,当客户成功注册后,我需要向客户发送短信。当我在芭蕾舞演员中使用Twilio连接器发送短信时,出现以下错误。

404 Not Found-:The requested resource /2010-04-01/Accounts//SMS/ 
Messages.json was not found.        

下面显示了与Twilio集成相关的代码,

import wso2/twilio;
twilio:Client twilioClient = new({
    accountSId: config:getAsString(TWILIO_ACCOUNT_SID),
    authToken: config:getAsString(TWILIO_AUTH_TOKEN)
});

我在ballerina.conf文件中也包含了Twilio-Sid和Auth Token。下面显示了我编写的通过Twilio-connector发送短信的功能

function sendSmsToCustomers(string mobile) returns boolean {

    boolean isSuccess= false;
    string toMobile = mobile;
    string messageBody = config:getAsString(TWILIO_MESSAGE);
    string fromMobile = config:getAsString(TWILIO_FROM_MOBILE);
    string message = messageBody;
    var response = twilioClient->sendSms(fromMobile, toMobile,  message);
   if (response is twilio:SmsResponse) {
        if (response.sid != EMPTY_STRING) {
            log:printDebug("Twilio Connector -> SMS successfully sent to " + toMobile);
            return true;
        }
    } else {
        log:printDebug("Twilio Connector -> SMS failed sent to " + toMobile);
        log:printError(<string>response.detail().message);
    }
    return isSuccess;
}

预期输出应该是将短信发送到所提供的手机号码(toMobile)

2 个答案:

答案 0 :(得分:1)

这里的问题是 TWILIO_ACCOUNT_SID 没有从 ballerina.conf 文件中读取。 ballerina.conf 文件应具有以下配置属性,以便与您的代码匹配。

TWILIO_ACCOUNT_SID="your_account_sid"
TWILIO_AUTH_TOKEN="your_auth_token"
TWILIO_MESSAGE="your_message"
TWILIO_FROM_MOBILE="your_from_mobile_number"

答案 1 :(得分:0)

我面临类似的问题。 我在 Twilio/Rest/Client.php 中发现的 构造函数需要用户名、密码和其他详细信息。

<块引用>

public function __construct(string $username = null, string $password = null, string $accountSid = null, string $region = null, HttpClient $httpClient = null , 数组 $environment = null)

但是在用于库加载的 Twilio.php 中,它试图通过传递 SID 和 TOKEN 来创建 Client 对象。

很可能是共享的库代码不正确或版本不同