Error using the Twilio library to send an SMS

The code below give an error, “ERROR: the index ‘http’ does not exist”.
I’m following the sample.

Output when running the device code (see following):

2020-08-08T00:57:13.561 +00:00 | [Status] | Agent restarted: reload.
-- | -- | --
2020-08-08T00:57:15.449 +00:00 | [Status] | Device disconnected
2020-08-08T00:57:15.549 +00:00 | [Status] | Downloading new code; 2.37% program storage used
2020-08-08T00:57:15.643 +00:00 | [Device] | ERROR: the index 'response' does not exist
2020-08-08T00:57:15.644 +00:00 | [Device] | ERROR:   in main device_code:9

Code I’m using:

#require "Twilio.class.nut:1.0.0"
local twilio = Twilio(
    __VARS.ACCOUNT_SID,
    __VARS.ACCOUNT_AUTH_TOKEN,
    __VARS.ACCOUNT_PHONE_NUMBER
);
local recipientsNumber = __VARS.MY_PHONE_NUMBER;
local textMessage = "Hello there #1";
local response = twilio.send(recipientsNumber, textMessage);
server.log(response.statuscode + ": " + response.body);

I also tried with hard coded values:

#require "Twilio.class.nut:1.0.0"
twilio <- Twilio(
    "AC_________________________________",
    "_________________________________",
    "+1650________1"
);
recipientsNumber <- "+1650________2";
textMessage <- "Hello there #1";
response <- twilio.send(recipientsNumber, textMessage);
server.log(response.statuscode + ": " + response.body);

Note, I am a Twilio support engineer. I’m confident the account values are correct.

Is it possible that you’re getting mixed up between device code and agent code? Each imp has two bits of code running: one in the cloud, the agent code, which is the only one that can access Twilio or other internet services – and one on the device itself, which is the only one that can access pieces of attached hardware. Typically those two pieces of code work together – communicating using agent.send/device.send – to produce an entire working application.

Your log shows an error being thrown from the device code. But the Twilio library, and the listing you give, only work as agent code.

If you’re using our online IDE, you (by default) see the agent code and device code in separate panes, next to each other.

Peter

You are correct, I missed that part about library being on the Agent side. Right near the top of the documentation, “at the top of your agent code”.
Thanks, I’ll retest. Cheers