question

Rick Smith avatar image
Rick Smith asked Rick Smith commented

CS0103 exception when trying to send SMS

Trying this code to send SMS in C# it is throwing a CS0103 at this point:

var response = await extension.Sms().Post(requestBody); //name extension does not exist in current context.


The full code
public async void sendSms()
{
RestClient rc;
rc = new RestClient("id, "clientsecret", "https://platform.devtest.ringcentral.com");
var requestBody = new
{
text = "Test",
from = new { textFrom = "+15551212" },
to = new object[] { new { sendTo = "+15551231" } }
};
var response = await extension.Sms().Post(requestBody); //Can't get past this point.
}





sms and text messaging
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered Phong Vu commented

Check out this quick start sample code to use the SDK for sending SMS messages.

https://developers.ringcentral.com/guide/messaging/quick-start#c#

4 comments
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thanks, There seems to be a problem in

static private async Task read_extension_phone_number()

here
foreach (var record in resp.records) //This throws CS1061
//CompanyPhoneNumberInfo does not contain a definition for 'records'

there are also some other problems with the record variable

0 Likes 0 ·

Looks like your test account does not have any number. Can you check if the resp.records is null or an empty array?

0 Likes 0 ·
Rick Smith avatar image Rick Smith Phong Vu ♦♦ ·


Thanks, Can't tell it's telling me resp has nothing like records or features there is no definition for either one in the foreach. Anyway I looked at the account and there is a number for the account, is that it?

0 Likes 0 ·
Show more comments
Rick Smith avatar image
Rick Smith answered Phong Vu commented

I am usinh 3136362490

1 comment
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

I don't know why the phone-number endpoint return null from your account. It should at least return the main company number. But looking into your sandbox account, I see you don't have any other number added to the user "101".

screen-shot-2021-01-08-at-65207-am.png

You can login your sandbox service web, browse to the page as shown above, then click the Add Direct Number and follow the instructions to add a number to the user extension.

Test it again.

0 Likes 0 ·
Rick Smith avatar image
Rick Smith answered Phong Vu commented

Neither do I, That is not where I am getting the info from, I am using this. And there is no provision for adding a direct number?? I tried this with Python and it it worked fine...has something changed?
1610118486539.png


1610118486539.png (104.2 KiB)
5 comments
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

The site you visit is the RingCentral Developer portal. It is different than the sandbox account admin portal. To setup and config your sandbox such as adding new users, adding new numbers ect. you need to login https://service.devtest.ringcentral.com with your sandbox user's login credentials (not the login credentials for the dev portal!). Alternatively, you can click the "Sandbox Accounts" option from the view you showed above and click on the up-arrow which will log you in the sandbox admin portal.

I will investigate the C# later.

0 Likes 0 ·
Rick Smith avatar image Rick Smith Phong Vu ♦♦ ·

Okay, I see it now, I will have to get the password from them, strange something has changed as I was able to use the information above to send SMS (with Python). As far as the C# goes the only error(s) I could find where in the foreach statements.

Thanks

0 Likes 0 ·

After the code below, can you print the "resp" object as string and post it here.

var resp = await restClient.Restapi().Account().Extension().PhoneNumber().Get();

0 Likes 0 ·
Rick Smith avatar image Rick Smith Phong Vu ♦♦ ·

No, It is throwing CompanyPhoneNumberInfo does not contain a definition for 'for 'records'
I tried changing it to this:

CompanyPhoneNumberInfo resp = await restClient.Restapi().Account().Extension().PhoneNumber().Get();


then in the foreach I tried this:


foreach (CompanyPhoneNumberInfo record in resp.records)
{
foreach (CompanyPhoneNumberInfo feature in record.features)
{


Same exception.



0 Likes 0 ·

I asked you to print the response, not parsing it w/o knowing what it returns.

var response = await rc.Restapi().Account().Extension().PhoneNumber().Get();
dynamic jsonStr = JsonConvert.SerializeObject(response);
Console.WriteLine(jsonStr);


0 Likes 0 ·
Rick Smith avatar image
Rick Smith answered Phong Vu commented

Same result; CS1061 CompanyPhoneNumberInfo does not contain a definition for records

1 comment
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Comment out the foreach lines! Just print the response which will not have anything to do with the CompanyPhoneNumberInfo object.

0 Likes 0 ·
Rick Smith avatar image
Rick Smith answered Rick Smith commented

Nothing, It freezes. No exceptions nothing.

12 comments
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Once you could try Python code, can you use this Python code?

https://developers.ringcentral.com/guide/messaging/quick-start#python

1 Like 1 ·
Rick Smith avatar image Rick Smith Phong Vu ♦♦ ·

Thanks, I think I will try convincing them to use Python instead.

0 Likes 0 ·

Don't need to. I just want to see the differences between using the .Net SDK and the Python SDK in your particular case.

BTW, what is the RingCentral .Net SDK version are you using?

0 Likes 0 ·
Show more comments

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys