Giter VIP home page Giter VIP logo

twilio-salesforce's Introduction

Deprecation Notice

Note: this library is deprecated and not recommended for new work. Please see the Twilio Salesforce documentation for new work with Twilio and Salesforce.

Twilio Helper Library for Salesforce

Get ready to unleash the power of the Twilio cloud communications platform in Salesforce and Force.com! Soon you'll be building powerful voice and text messaging apps in Apex and Visualforce.

With this toolkit you'll be able to:

  • Make requests to Twilio's REST API
  • Control phone calls and respond to text messages in real time with TwiML
  • Embed Twilio Client in-browser calling in your Salesforce and Force.com apps

Installation

We've made it easy to get started. Just grab the code from GitHub and deploy it to your Salesforce org with the included Ant script.

Quick Install: If you do not have the existing Twilio-Salesforce library installed, you can use this unmanaged package to install: v4.2.0 https://login.salesforce.com/packaging/installPackage.apexp?p0=04t1a000000AQzf

v3.2.0 https://login.salesforce.com/packaging/installPackage.apexp?p0=04ti0000000XkE0

If you have a previous version of Twilio-Salesforce library installed, you will need to use Ant to install/update:

  1. Checkout or download the twilio-salesforce library from GitHub.

    $ git clone [email protected]:twilio/twilio-salesforce.git
  2. Install the Force.com Migration Tool plugin for Ant, if you don't already have it.

  3. Edit install/build.properties to insert your Salesforce username and password. Since you will be using the API to access Salesforce, remember to append your Security Token to your password.

  4. Open your command line to the install folder, then deploy using Ant:

    $ ant deployTwilio

Now all the library code is in your org and you're ready to start coding!

Quickstart

Getting started with the Twilio API couldn't be easier. Create a Twilio REST client to get started. For example, the following code makes a call using the Twilio REST API.

Make a Call

This sample calls the to phone number and plays music. The from number must be a verified number on your Twilio account.

// Find your Twilio API credentials at https://www.twilio.com/user/account
String account = 'ACXXXXXXXXXXXXXXXXX';
String token = 'YYYYYYYYYYYYYYYYYY';

TwilioRestClient client = new TwilioRestClient(account, token);

Map<String,String> params = new Map<String,String> {
        'To'   => '9991231234',
        'From' => '9991231234',
        'Url'  => 'http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient'
    };
TwilioCall call = client.getAccount().getCalls().create(params);

Send an SMS

This sample texts Hello there! to the to phone number. The from number must be a number which you have purchased from Twilio. Unlike voice calls, SMS messages cannot be sent from a verified number.

String account = 'ACXXXXXXXXXXXXXXXXX';
String token = 'YYYYYYYYYYYYYYYYYY';
TwilioRestClient client = new TwilioRestClient(account, token);

Map<String,String> params = new Map<String,String> {
        'To'   => '+12316851234',
        'From' => '+15555555555',
        'Body' => 'Hello there!'
    };
TwilioSMS sms = client.getAccount().getSMSMessages().create(params);

Generate TwiML

To control phone calls, your application needs to output TwiML. Use TwilioTwiML.Response to easily create a TwiML document.

TwilioTwiML.Response r = new TwilioTwiML.Response();
TwilioTwiML.Play p = new TwilioTwimL.Play('https://api.twilio.com/cowbell.mp3');
p.setLoop(5);
r.append(p);
System.debug(r.toXML());
<Response><Play loop="5">https://api.twilio.com/cowbell.mp3</Play><Response>

Next Steps

The full power of the Twilio API is at your fingertips. Visit the full documentation for advanced topics.

twilio-salesforce's People

Contributors

alexcchan avatar andrewmbenton avatar beans0063 avatar brettgerry avatar choppen5 avatar dschach avatar johnsheehan avatar kwhinnery avatar pkamp3 avatar raghusagar avatar skimbrel avatar tmcmanus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

twilio-salesforce's Issues

Installation

I'm trying to follow the instructions and can't seem to get the deployment to actually work. When I type the command "ant deployTwilio" it gives me the error that "objects/TwilioConfig__c.object -- Error: TwilioConfig__c: Cannot change Custom Settings Type".

I've Googled and don't know how to address or fix this issue - can you help?

TwilioRestException: Script-thrown exception

Installed the package into production and sandbox, tried migrating other code into production but had the following test failures:

Class Twilio_TestApplication
Method Name testTwilioAplications_filter
Pass/Fail Fail
Error Message TwilioRestException: Script-thrown exception
Stack Trace Class.TwilioRestClient: line 591, column 1
Class.TwilioResource: line 82, column 1
Class.TwilioResource.ListResource: line 463, column 1
Class.TwilioApplicationList: line 80, column 1
Class.Twilio_TestApplication.testTwilioAplications_filter: line 145, column 1

Class Twilio_TestApplication
Method Name testTwilioAplications_get
Pass/Fail Fail
Error Message TwilioRestException: Script-thrown exception
Stack Trace Class.TwilioRestClient: line 591, column 1
Class.TwilioResource: line 82, column 1
Class.TwilioResource.ListResource: line 463, column 1
Class.TwilioApplicationList: line 80, column 1
Class.Twilio_TestApplication.testTwilioAplications_get: line 66, column 1

Class Twilio_TestPhoneNumbers
Method Name testTwilioAvailablePhoneNumbers_AreaCodeFilter
Pass/Fail Fail
Error Message TwilioRestException: Script-thrown exception
Stack Trace Class.TwilioRestClient: line 591, column 1
Class.TwilioResource: line 82, column 1
Class.TwilioResource.ListResource: line 463, column 1
Class.TwilioAvailablePhoneNumberList: line 106, column 1
Class.Twilio_TestPhoneNumbers.testTwilioAvailablePhoneNumbers_AreaCodeFilter: line 274, column 1

Error: "This method currently only supports JSON responses, not XML"

Discovered that he content type as returned by Twilio is occasionally "contentType=application/json; charset=utf-8". However, the code in the twilioRestResponse class, line 209, checks for the following: this.contentType.equalsIgnoreCase('application/json')

I fixed the problem locally by modifying the twilioRestResponse class on line 209 to change equalsIgnoreCase() to startsWithIgnoreCase().

Full details are here: http://gsfn.us/t/4btdo

ant deployTwilio failure [Twilio_TestConference.testTwilioParticipants_get -- TwilioRestException: Script-thrown exception]

$ ant deployTwilio
Buildfile: /Users/samrudhipatil/codebase/twilio-salesforce-master/install/build.xml

deployTwilio:
[echo] Deploying Twilio Helper Library for Salesforce...
[sf:deploy] Request for a deploy submitted successfully.
[sf:deploy] Request ID for the current deploy task: 0Af60000000F5iaCAC
[sf:deploy] Waiting for server to finish processing the request...
[sf:deploy] Request Status: InProgress
[sf:deploy] Request Status: InProgress (0/76) -- Processing Type: CustomObject
[sf:deploy] Request Status: InProgress (4/76) -- Processing Type: ApexClass
[sf:deploy] Request Status: InProgress (4/76) -- Processing Type: ApexClass
[sf:deploy] Request Status: InProgress (4/76) -- Processing Type: ApexClass
[sf:deploy] Request Status: InProgress
[sf:deploy] Request Status: InProgress
[sf:deploy] Request Status: InProgress
[sf:deploy] Request Status: InProgress
[sf:deploy] Request Status: InProgress
[sf:deploy] Request Status: InProgress
[sf:deploy] Request Status: InProgress (0/268) -- Running Test: addAttachedByContactIdTest.myUnitTest
[sf:deploy] Request Status: InProgress (3/268) -- Running Test: addCases_Test.theTests
[sf:deploy] Request Status: InProgress (7/268) -- Running Test: addPartnerUsersToGroupTest.TestUpdatePartnerUsersToGroup
[sf:deploy] Request Status: InProgress (9/268) -- Running Test: ApprovalQuoteLineController.test
[sf:deploy] Request Status: InProgress (10/268) -- Running Test: AssetReturnRequestTest.myUnitTest
[sf:deploy] Request Status: InProgress (21/268) -- Running Test: CallCenterCaseNotification.testAddRegionContact
[sf:deploy] Request Status: InProgress (26/268) -- Running Test: CampaigmMemberTriggerHandlerClassTest.TestMothod1
[sf:deploy] Request Status: InProgress (29/268) -- Running Test: caseCustProfile_Test.theTests
[sf:deploy] Request Status: InProgress (39/268) -- Running Test: CaseWatchdogTest.testBuildEmailList
[sf:deploy] Request Status: InProgress (46/268) -- Running Test: DisplayAssociatedAssetConfigurationTest.testMethod1
[sf:deploy] Request Status: InProgress (53/268) -- Running Test: LicenseUIController.testInvokeMethodsForCoverage
[sf:deploy] Request Status: InProgress (53/268) -- Running Test: LicenseUIController.testInvokeMethodsForCoverage
[sf:deploy] Request Status: InProgress (53/268) -- Running Test: LicenseUIController.testInvokeMethodsForCoverage
[sf:deploy] Request Status: InProgress (60/268) -- Running Test: LicenseUtilityController.testgenerateLicenseFileForReclaimWorkflow
[sf:deploy] Request Status: InProgress (70/268) -- Running Test: NotificationController.testsendEmail
[sf:deploy] Request Status: InProgress (73/268) -- Running Test: NtnxGenerateLicensesTest.testGenerateLicenses
[sf:deploy] Request Status: InProgress (77/268) -- Running Test: NtnxPlatPlusRequestControllerTest.myUnitTest
[sf:deploy] Request Status: InProgress (80/268) -- Running Test: NtnxUtilityExtension.testGetTAMPresent
[sf:deploy] Request Status: InProgress (98/268) -- Running Test: OpportunityExtensionTest.testOpportunityExtension
[sf:deploy] Request Status: InProgress (100/268) -- Running Test: OppSalesOrderRelatedListControllerTests.testInit
[sf:deploy] Request Status: InProgress (107/268) -- Running Test: populateEmailNotificationFieldsTest.myUnitTest
[sf:deploy] Request Status: InProgress (116/268) -- Running Test: SalesOrderUtilTest.testComma
[sf:deploy] Request Status: InProgress (120/268) -- Running Test: SbqqQuoteUtilTest.myUnitTest
[sf:deploy] Request Status: InProgress (120/268) -- Running Test: SbqqQuoteUtilTest.myUnitTest
[sf:deploy] Request Status: InProgress (120/268) -- Running Test: SbqqQuoteUtilTest.myUnitTest
[sf:deploy] Request Status: InProgress (129/268) -- Running Test: selfRegistrationController.getAccountNameTest
[sf:deploy] Request Status: InProgress (136/268) -- Running Test: SurveyContestHandlerTest.testFoundWinnerNotificationEmail
[sf:deploy] Request Status: InProgress (147/268) -- Running Test: TEST_CaseHandoffTimer.testPutCaseIntoQueue
[sf:deploy] Request Status: InProgress (150/268) -- Running Test: testCeligoExplodeItemBundle.myUnitTest
[sf:deploy] Request Status: InProgress (156/268) -- Running Test: testTriggers.testTrigger
[sf:deploy] Request Status: InProgress (168/268) -- Running Test: Twilio_TestCalls.testTwilioCall_cancel
[sf:deploy] Request Status: InProgress (199/268) -- Running Test: Twilio_TestNotification.testTwilioNotication_get
[sf:deploy] -----------------------------------------------------------------------------------
[sf:deploy] Test Failures:
[sf:deploy] 1. Twilio_TestConference.testTwilioParticipants_get -- TwilioRestException: Script-thrown exception
[sf:deploy] Stack trace: Class.TwilioRestClient: line 591, column 1
[sf:deploy] Class.TwilioResource: line 82, column 1
[sf:deploy] Class.TwilioResource.ListResource: line 463, column 1
[sf:deploy] Class.TwilioParticipantList: line 87, column 1
[sf:deploy] Class.Twilio_TestConference.testTwilioParticipants_get: line 212, column 1
[sf:deploy] -----------------------------------------------------------------------------------
[sf:deploy] Request Status: InProgress (229/268) -- Running Test: Twilio_TestRestExceptn.test
[sf:deploy] Request Status: InProgress (256/268) -- Running Test: updatePartnerCourseonAccountCtrlerTest.testinsertPartnerCourse
[sf:deploy] Request Status: InProgress (262/268) -- Running Test: webservicesNetexamComUserservice71Test.DeactivateUserByExternalIDTest
[sf:deploy] Request Status: InProgress (266/268) -- Running Test: webservicesNetexamComUserservice71Test.UpsertUserTest
[sf:deploy] Request Status: Failed

BUILD FAILED
/Users/samrudhipatil/codebase/twilio-salesforce-master/install/build.xml:9:
*********** DEPLOYMENT FAILED ***********
Request ID: 0Af60000000F5iaCAC

All Test Failures:

  1. Twilio_TestConference.testTwilioParticipants_get -- TwilioRestException: Script-thrown exception
    Stack trace: Class.TwilioRestClient: line 591, column 1
    Class.TwilioResource: line 82, column 1
    Class.TwilioResource.ListResource: line 463, column 1
    Class.TwilioParticipantList: line 87, column 1
    Class.Twilio_TestConference.testTwilioParticipants_get: line 212, column 1
    *********** DEPLOYMENT FAILED ***********

Total time: 8 minutes 20 seconds

Can't clone the repository.

Error:
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Documentation out of date. (uses SMSMessage class in example)

The existing documentation for the library as presented here https://github.com/twilio/twilio-salesforce and on the Twilio-Salesforce documentation. Uses SMSMessage class in examples. According to customer support, this is deprecated methodology and new development should use the Message class.

I do not see a Method breakdown either for either the SMSMessage class or the Message class i.e. without assessing the source code it's impossible to identify that on demand request for a specific Message is possible via the .getMessage('id of message')

Customer support has asked me to raise the issue here.

TwilioCapability.cls testGenerateParamString test depends on Map entry ordering

The test here:

https://github.com/twilio/twilio-salesforce/blob/master/src/classes/TwilioCapability.cls#L275

    System.assertEquals('split%2Bkey2=split%2Bval2&split+key1=split+val1', generateParamString(new Map<String,String> {'split key1'=>'split val1', 'split+key2'=>'split+val2'} ));

doesn't always pass because the generated string assumes that map entries are iterated through in a certain order here:

https://github.com/twilio/twilio-salesforce/blob/master/src/classes/TwilioCapability.cls#L197

TwilioRestException properties are private

I had been trying to trap twilio exceptions using a try/catch block, but discovered that the only error message returned was "unknown script exception". The root cause appears to be that the errorCode, message, moreInfo and status properties in the TwilioRestException class are private. Changing these to public allows the full error detail to be retrieved in the following code block:

try {
    TwilioSms sms = twilioAccount.getSmsMessages().create(params);
} catch (TwilioRestException e) {
    system.debug(LoggingLevel.Error, '  * Twilio Error=' + e.errorCode
    + '/' + e.message);
} catch (exception ex) { 
    /* other code */
}

More info: http://gsfn.us/t/4byl5

Best Regards,

Mike

IncomingPhoneNumberList doesn't set requestAccountSid on its instances

So the following does not work:

TwilioRestClient client = TwilioAPI.getDefaultClient();
Map<String, String> params = new Map<String, String>();
params.put('PhoneNumber', '<some number>');
TwilioIncomingPhoneNumber phone = client.getAccount().getIncomingPhoneNumbers(params).getPageData()[0];
phone.updateResource(new Map<String, String>{'VoiceUrl' => 'http://example.com'});

Adding a call to phone.setRequestAccountSid('AC123') before calling updateResource() makes this work. List resources should be doing this in their parseResponse methods so that updating their instance elements works. Should audit all of the other resources when we fix this.

Twilio/ Salesforce Softphone not working

Hi,

I've installed Twilio in one of my client's Org. And followed all the steps of configuration(https://moometric.com/integrations/sf/salesforce-open-cti-lightning-with-twilio-tutorial/).

But facing the same issue mentioned in the above link,

Issue:

Uncaught Error: Unable to make a call. Contact your admin. throws at https://alu--tfsb2--c.cs85.visual.force.com/components/c/callInitiatedPanel.js:57:37

Please help me with fixing this issue.

I've one more requirement on same Twilio, If a number is dialed from the dialer or any outbound call is in progress with the Twilio and the receiver won't receive the call or call get disconnected then there should be a pop-up message with the reason on the dialer screen.

image

Thanks!

TwilioCapability Test assertion failing. Please fix it.

Hello, When i run the test cases one of the test case is failing. Line 276 as follows.

    System.assertEquals('split%2Bkey2=split%2Bval2&split+key1=split+val1', generateParamString(new Map<String,String> {'split key1'=>'split val1', 'split+key2'=>'split+val2'} ));

I have change it as below and it's working. Seems like some encoding issue.

    System.assertEquals('split+key2=split+val2&split+key1=split+val1', generateParamString(new Map<String,String> {'split key1'=>'split val1', 'split key2'=>'split val2'} ));

10:19:23.782 (4782375000)|METHOD_EXIT|[276]|01pd0000002MH7h|TwilioCapability.generateParamString(MAP<String,String>)
10:19:23.782 (4782430000)|EXCEPTION_THROWN|[276]|System.AssertException: Assertion Failed: Expected: split%2Bkey2=split%2Bval2&split+key1=split+val1, Actual: split+key1=split+val1&split%2Bkey2=split%2Bval2
10:19:23.782 (4782553000)|FATAL_ERROR|System.AssertException: Assertion Failed: Expected: split%2Bkey2=split%2Bval2&split+key1=split+val1, Actual: split+key1=split+val1&split%2Bkey2=split%2Bval2

Class.TwilioCapability.testGenerateParamString: line 276, column 1
10:19:23.782 (4782567000)|FATAL_ERROR|System.AssertException: Assertion Failed: Expected: split%2Bkey2=split%2Bval2&split+key1=split+val1, Actual: split+key1=split+val1&split%2Bkey2=split%2Bval2

Class.TwilioCapability.testGenerateParamString: line 276, column 1

Let me know once you have new version.

Thanks for your help,
Rama

Twilio_TestPhoneNumbers: Test failure preventing deployment

I am getting the below error when trying to deploy this to production.

API Name: Twilio_TestPhoneNumbers
Apex Class
Line: 106
Column: 31
Error Message:
Method does not exist or incorrect signature: [TwilioAvailablePhoneNumber].getAddressRequirements()

Line 106 of Twilio_TestPhoneNumbers is:

System.assertEquals('none', phnumber0.getAddressRequirements());

The method in TwilioAvailablePhoneNumber is there:

Line 157

/**
* Indicates whether this number requires an Address to be on file with Twilio.
* Potential values are "any", "local", "foreign", or "none".
*
* @return the address requirements
*/
public String getAddressRequirements() {
return this.getProperty('address_requirements');
}

I was experiencing the Script Thrown error on the Twilio_TestPhoneNumbers class and added

map<string,string> params=new map<string,string>();
params.put('AreaCode','510');
params.put('Contains','51034*****');

To that class.

Now I get the above error.

Any help is appreciated!

Twilio_TestPhoneNumbers.cls
`/*
Copyright (c) 2012 Twilio, Inc.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
@istest
private class Twilio_TestPhoneNumbers {

final static String authToken = '12345678901234567890123456789012';
	
static testmethod void testTwilioAvailablePhoneNumbers_US_Local() {
    String accountJsonResponseBody =
    	'{'
		+'"uri": "/2010-04-01/Accounts/ACde6f1e11047ebd6fe7a55f120be3a900/AvailablePhoneNumbers/US/Local.json?AreaCode=510",'
		+'"available_phone_numbers": ['
			+'{'
				+'"friendly_name": "(510) 564-7903",'
				+'"phone_number": "+15105647903",'
				+'"lata": "722",'
				+'"rate_center": "OKLD TRNID",'
				+'"latitude": "37.780000",'
				+'"longitude": "-122.380000",'
				+'"region": "CA",'
				+'"postal_code": "94703",'
				+'"iso_country": "US",'
				+'"address_requirements": "none",'
  				+'"beta": false,'
	            +'"capabilities":{'
	                +'"voice": true,'
	                +'"SMS": true,'
	                +'"MMS": false'
	            +'}'      									
			+'},'
			+'{'
				+'"friendly_name": "(510) 488-4379",'
				+'"phone_number": "+15104884379",'
				+'"lata": "722",'
				+'"rate_center": "OKLD FRTVL",'
				+'"latitude": "37.780000",'
				+'"longitude": "-122.380000",'
				+'"region": "CA",'
				+'"postal_code": "94602",'
				+'"iso_country": "US",'
				+'"address_requirements": "none",'
  				+'"beta": false,'
	            +'"capabilities":{'
	                +'"voice": true,'
	                +'"SMS": true,'
	                +'"MMS": false'
	            +'}'      									
			+'}'
		+']}';
    
    
    // register a mock Response with the Twilio_TestHTTPMock singleton service
	// for the HTTP GET method and at the Twilio Account instance URI.
	Twilio_TestHTTPMock.getInstance().putResponse(
		'GET',
		'https://api.twilio.com/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/AvailablePhoneNumbers/US/Local.json',
		new Twilio_TestHTTPMock.Response(accountJsonResponseBody,200)
		);

	map<string,string> params=new map<string,string>();
		params.put('AreaCode','510');
		params.put('Contains','51034*****');

	// Get an API client and request the Twilio Account
	TwilioRestClient client = new TwilioRestClient('ACba8bc05eacf94afdae398e642c9cc32d', authToken);
	TwilioAvailablePhoneNumberList twnumbers = client.getAccount().getAvailablePhoneNumbers();
	
	// assert correct values in the fields
	System.assertNotEquals(null, twnumbers);
	
	List<TwilioAvailablePhoneNumber> phnumbersList = twnumbers.getPageData();
	
	System.assertNotEquals(null, phnumbersList);
	System.assertEquals(2, phnumbersList.size());
	
	TwilioAvailablePhoneNumber phnumber0 = phnumbersList.get(0);
	System.assertEquals('(510) 564-7903', phnumber0.getFriendlyName());
	System.assertEquals('+15105647903', phnumber0.getPhoneNumber());
	System.assertEquals('722', phnumber0.getLata());
	System.assertEquals('OKLD TRNID', phnumber0.getRateCenter());
	System.assertEquals('37.780000', phnumber0.getLatitude());
	System.assertEquals('-122.380000', phnumber0.getLongitude());
	System.assertEquals('CA', phnumber0.getRegion());
	System.assertEquals('94703', phnumber0.getPostalCode());
	System.assertEquals('US', phnumber0.getIsoCountry());
	System.assertEquals('none', phnumber0.getAddressRequirements());
	System.assertEquals(false, phnumber0.getBeta());
	System.assertEquals(true, Boolean.valueOf(phnumber0.getCapabilities().get('voice')));
	System.assertEquals(true, Boolean.valueOf(phnumber0.getCapabilities().get('SMS')));
	System.assertEquals(false, Boolean.valueOf(phnumber0.getCapabilities().get('MMS')));

	TwilioAvailablePhoneNumber phnumber1 = phnumbersList.get(1);
	System.assertEquals('(510) 488-4379', phnumber1.getFriendlyName());
	System.assertEquals('+15104884379', phnumber1.getPhoneNumber());
	System.assertEquals('722', phnumber1.getLata());
	System.assertEquals('OKLD FRTVL', phnumber1.getRateCenter());
	System.assertEquals('37.780000', phnumber1.getLatitude());
	System.assertEquals('-122.380000', phnumber1.getLongitude());
	System.assertEquals('CA', phnumber1.getRegion());
	System.assertEquals('94602', phnumber1.getPostalCode());
	System.assertEquals('US', phnumber1.getIsoCountry());
	System.assertEquals('none', phnumber1.getAddressRequirements());
	System.assertEquals(false, phnumber1.getBeta());
	System.assertEquals(true, Boolean.valueOf(phnumber1.getCapabilities().get('voice')));
	System.assertEquals(true, Boolean.valueOf(phnumber1.getCapabilities().get('SMS')));
	System.assertEquals(false, Boolean.valueOf(phnumber1.getCapabilities().get('MMS')));
	
	Exception e = null;
	try {
		phnumber1.getResourceLocation();
	} catch (Exception e1) {
		e = e1;
	}
	System.assert(e instanceof TwilioRestException);
    
    Iterator<TwilioAvailablePhoneNumber> it = twnumbers.iterator();
    System.assertEquals(true, it.hasNext());
    phnumber0 = it.next();
	System.assertEquals('(510) 564-7903', phnumber0.getFriendlyName());
	System.assertEquals('+15105647903', phnumber0.getPhoneNumber());
	System.assertEquals('722', phnumber0.getLata());
	System.assertEquals('OKLD TRNID', phnumber0.getRateCenter());
	System.assertEquals('37.780000', phnumber0.getLatitude());
	System.assertEquals('-122.380000', phnumber0.getLongitude());
	System.assertEquals('CA', phnumber0.getRegion());
	System.assertEquals('94703', phnumber0.getPostalCode());
	System.assertEquals('US', phnumber0.getIsoCountry());
	
	System.assertEquals(true, it.hasNext());
	phnumber1 = it.next();
	System.assertEquals('(510) 488-4379', phnumber1.getFriendlyName());
	System.assertEquals('+15104884379', phnumber1.getPhoneNumber());
	System.assertEquals('722', phnumber1.getLata());
	System.assertEquals('OKLD FRTVL', phnumber1.getRateCenter());
	System.assertEquals('37.780000', phnumber1.getLatitude());
	System.assertEquals('-122.380000', phnumber1.getLongitude());
	System.assertEquals('CA', phnumber1.getRegion());
	System.assertEquals('94602', phnumber1.getPostalCode());
	System.assertEquals('US', phnumber1.getIsoCountry());
	
	System.assertEquals(false, it.hasNext());
}

static testmethod void testTwilioAvailablePhoneNumbers_US_Tollfree() {
	String accountJsonResponseBody =
    	'{"available_phone_numbers":[{"friendly_name":"(866) 231-5481","phone_number":"+18662315481","iso_country":"US"},'+
    	'{"friendly_name":"(866) 205-6833","phone_number":"+18662056833","iso_country":"US"},{"friendly_name":"(877) 349-2687",'+
    	'"phone_number":"+18773492687","iso_country":"US"},{"friendly_name":"(888) 293-0129","phone_number":"+18882930129","iso_country":"US"}],'
    	+'"uri":"/2010-04-01/Accounts/AC03c2fcd60e144e7cbeed179fcbf812a3/AvailablePhoneNumbers/US/TollFree.json"}';
		Twilio_TestHTTPMock.getInstance().putResponse(
		'GET',
		'https://api.twilio.com/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/AvailablePhoneNumbers/US/TollFree.json',
		new Twilio_TestHTTPMock.Response(accountJsonResponseBody,200)
		);
	
		// Get an API client and request the Twilio Account
		TwilioRestClient client = new TwilioRestClient('ACba8bc05eacf94afdae398e642c9cc32d', authToken);
		TwilioAvailablePhoneNumberList twnumbers = client.getAccount().getAvailablePhoneNumbers(new map<string,string>(), 'US','TollFree');
		
		// assert correct values in the fields
		System.assertNotEquals(null, twnumbers);
		
		List<TwilioAvailablePhoneNumber> phnumbersList = twnumbers.getPageData();
		
		System.assertNotEquals(null, phnumbersList);
		System.assertEquals(4, phnumbersList.size());			
		
		System.assertEquals('(866) 231-5481', phnumbersList[0].getFriendlyName());
		System.assertEquals('+18662315481', phnumbersList[0].getPhoneNumber());
		System.assertEquals('US', phnumbersList[0].getIsoCountry());
		
		System.assertEquals('(866) 205-6833', phnumbersList[1].getFriendlyName());
		System.assertEquals('+18662056833', phnumbersList[1].getPhoneNumber());
		System.assertEquals('US', phnumbersList[1].getIsoCountry());
		
		System.assertEquals('(877) 349-2687', phnumbersList[2].getFriendlyName());
		System.assertEquals('+18773492687', phnumbersList[2].getPhoneNumber());
		System.assertEquals('US', phnumbersList[2].getIsoCountry());
		
		System.assertEquals('(888) 293-0129', phnumbersList[3].getFriendlyName());
		System.assertEquals('+18882930129', phnumbersList[3].getPhoneNumber());
		System.assertEquals('US', phnumbersList[3].getIsoCountry());
		
		
		Iterator<TwilioAvailablePhoneNumber> it = twnumbers.iterator();
        System.assertEquals(true, it.hasNext());
        TwilioAvailablePhoneNumber phnumber0 = it.next();
        
        System.assertEquals('(866) 231-5481', phnumber0 .getFriendlyName());
		System.assertEquals('+18662315481', phnumber0 .getPhoneNumber());
		System.assertEquals('US', phnumber0 .getIsoCountry());
		System.assertEquals(true, it.hasNext());
		phnumber0 = it.next();
		
		System.assertEquals('(866) 205-6833', phnumber0.getFriendlyName());
		System.assertEquals('+18662056833', phnumber0.getPhoneNumber());
		System.assertEquals('US', phnumber0.getIsoCountry());
		System.assertEquals(true, it.hasNext());
		phnumber0 = it.next();
		
		System.assertEquals('(877) 349-2687', phnumber0.getFriendlyName());
		System.assertEquals('+18773492687', phnumber0.getPhoneNumber());
		System.assertEquals('US', phnumber0.getIsoCountry());
		System.assertEquals(true, it.hasNext());
		phnumber0 = it.next();
		
		System.assertEquals('(888) 293-0129', phnumber0.getFriendlyName());
		System.assertEquals('+18882930129', phnumber0.getPhoneNumber());
		System.assertEquals('US', phnumber0.getIsoCountry());
        System.assertEquals(false, it.hasNext());
		
		
}

static testmethod void testTwilioAvailablePhoneNumbers_UK() {
	String accountJsonResponseBody =
    	'{"available_phone_numbers":[{"friendly_name":"(866) 231-5481","phone_number":"+448662315481","iso_country":"UK"},'+
    	'{"friendly_name":"(866) 205-6833","phone_number":"+448662056833","iso_country":"UK"},{"friendly_name":"(877) 349-2687",'+
    	'"phone_number":"+448773492687","iso_country":"UK"},{"friendly_name":"(888) 293-0129","phone_number":"+448882930129","iso_country":"UK"}],'
    	+'"uri":"/2010-04-01/Accounts/AC03c2fcd60e144e7cbeed179fcbf812a3/AvailablePhoneNumbers/US/TollFree.json"}';
		Twilio_TestHTTPMock.getInstance().putResponse(
		'GET',
		'https://api.twilio.com/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/AvailablePhoneNumbers/UK/TollFree.json',
		new Twilio_TestHTTPMock.Response(accountJsonResponseBody,200)
		);
	
		// Get an API client and request the Twilio Account
		TwilioRestClient client = new TwilioRestClient('ACba8bc05eacf94afdae398e642c9cc32d', authToken);
		TwilioAvailablePhoneNumberList twnumbers = client.getAccount().getAvailablePhoneNumbers(new map<string,string>(), 'UK','TollFree');
		
		// assert correct values in the fields
		System.assertNotEquals(null, twnumbers);
		
		List<TwilioAvailablePhoneNumber> phnumbersList = twnumbers.getPageData();
		
		System.assertNotEquals(null, phnumbersList);
		System.assertEquals(4, phnumbersList.size());			
		
		System.assertEquals('(866) 231-5481', phnumbersList[0].getFriendlyName());
		System.assertEquals('+448662315481', phnumbersList[0].getPhoneNumber());
		System.assertEquals('UK', phnumbersList[0].getIsoCountry());
		
		System.assertEquals('(866) 205-6833', phnumbersList[1].getFriendlyName());
		System.assertEquals('+448662056833', phnumbersList[1].getPhoneNumber());
		System.assertEquals('UK', phnumbersList[1].getIsoCountry());
		
		System.assertEquals('(877) 349-2687', phnumbersList[2].getFriendlyName());
		System.assertEquals('+448773492687', phnumbersList[2].getPhoneNumber());
		System.assertEquals('UK', phnumbersList[2].getIsoCountry());
		
		System.assertEquals('(888) 293-0129', phnumbersList[3].getFriendlyName());
		System.assertEquals('+448882930129', phnumbersList[3].getPhoneNumber());
		System.assertEquals('UK', phnumbersList[3].getIsoCountry());
}

static testmethod void testTwilioAvailablePhoneNumbers_AreaCodeFilter() {
	String accountJsonResponseBody =
    	'{"available_phone_numbers":[{"friendly_name":"(510) 342-3750","phone_number":"+15103423750","latitude":"37.660000",'
    	+'"longitude":"-122.070000","region":"CA","postal_code":"94578","iso_country":"US","lata":"722","rate_center":"HAYWARD"},'
    	+'{"friendly_name":"(510) 343-6640","phone_number":"+15103436640","latitude":"37.810000",'
    	+'"longitude":"-122.260000","region":"CA","postal_code":"94617","iso_country":"US","lata":"722","rate_center":"OKLD TRNID"}],'
    	+'"uri":"/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/AvailablePhoneNumbers/US/Local.json?AreaCode=510&Contains=51034*****"}';
		Twilio_TestHTTPMock.getInstance().putResponse(
		'GET',
		'https://api.twilio.com/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/AvailablePhoneNumbers/US/Local.json?AreaCode=510&Contains=51034*****',
		new Twilio_TestHTTPMock.Response(accountJsonResponseBody,200)
		);
	
		map<string,string> params=new map<string,string>();
		params.put('AreaCode','510');
		params.put('Contains','51034*****');

		// Get an API client and request the Twilio Account
		TwilioRestClient client = new TwilioRestClient('ACba8bc05eacf94afdae398e642c9cc32d', authToken);
		TwilioAvailablePhoneNumberList twnumbers = client.getAccount().getAvailablePhoneNumbers(params, 'US','Local');
		
		// assert correct values in the fields
		System.assertNotEquals(null, twnumbers);
		
		List<TwilioAvailablePhoneNumber> phnumbersList = twnumbers.getPageData();
	
	System.assertNotEquals(null, phnumbersList);
	System.assertEquals(2, phnumbersList.size());		
	TwilioAvailablePhoneNumber phnumber0 = phnumbersList.get(0);
	System.assertEquals('(510) 342-3750', phnumber0.getFriendlyName());
	System.assertEquals('+15103423750', phnumber0.getPhoneNumber());
	System.assertEquals('722', phnumber0.getLata());
	System.assertEquals('HAYWARD', phnumber0.getRateCenter());
	System.assertEquals('37.660000', phnumber0.getLatitude());
	System.assertEquals('-122.070000', phnumber0.getLongitude());
	System.assertEquals('CA', phnumber0.getRegion());
	System.assertEquals('94578', phnumber0.getPostalCode());
	System.assertEquals('US', phnumber0.getIsoCountry());
	
	TwilioAvailablePhoneNumber phnumber1 = phnumbersList.get(1);
	System.assertEquals('(510) 343-6640', phnumber1.getFriendlyName());
	System.assertEquals('+15103436640', phnumber1.getPhoneNumber());
	System.assertEquals('722', phnumber1.getLata());
	System.assertEquals('OKLD TRNID', phnumber1.getRateCenter());
	System.assertEquals('37.810000', phnumber1.getLatitude());
	System.assertEquals('-122.260000', phnumber1.getLongitude());
	System.assertEquals('CA', phnumber1.getRegion());
	System.assertEquals('94617', phnumber1.getPostalCode());
	System.assertEquals('US', phnumber1.getIsoCountry());

	TwilioAvailablePhoneNumberList twnumbers1 =new TwilioAvailablePhoneNumberList(client);
	TwilioAvailablePhoneNumberList twnumbers2 =new TwilioAvailablePhoneNumberList(client,'US','Local');
	TwilioAvailablePhoneNumber avtwnumbers1 =new TwilioAvailablePhoneNumber(client);
	
}

static testMethod void testTwilioAvailabePoneNumber_Purchase() {
	String accountJsonResponseBody =
    	'{"available_phone_numbers":[{"friendly_name":"(510) 342-3750","phone_number":"+15103423750","latitude":"37.660000",'
    	+'"longitude":"-122.070000","region":"CA","postal_code":"94578","iso_country":"US","lata":"722","rate_center":"HAYWARD"},'
    	+'{"friendly_name":"(510) 343-6640","phone_number":"+15103436640","latitude":"37.810000",'
    	+'"longitude":"-122.260000","region":"CA","postal_code":"94617","iso_country":"US","lata":"722","rate_center":"OKLD TRNID"}],'
    	+'"uri":"/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/AvailablePhoneNumbers/US/Local.json?AreaCode=510&Contains=51034*****"}';
		Twilio_TestHTTPMock.getInstance().putResponse(
		'GET',
		'https://api.twilio.com/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/AvailablePhoneNumbers/US/Local.json?AreaCode=510&Contains=51034*****',
		new Twilio_TestHTTPMock.Response(accountJsonResponseBody,200)
		);
	
		map<string,string> params=new map<string,string>();
		params.put('AreaCode','510');
		params.put('Contains','51034*****');

		// Get an API client and request the Twilio Account
		TwilioRestClient client = new TwilioRestClient('ACba8bc05eacf94afdae398e642c9cc32d', authToken);
		TwilioAvailablePhoneNumberList twnumbers = client.getAccount().getAvailablePhoneNumbers(params, 'US','Local');
		
		
		List<TwilioAvailablePhoneNumber> phnumbersList = twnumbers.getPageData();
		TwilioAvailablePhoneNumber phnumber0 = phnumbersList.get(0);


	String purchaseResponseBody ='{"sid": "PN2a0747eba6abf96b7e3c3ff0b4530f6e","account_sid": "ACba8bc05eacf94afdae398e642c9cc32d","friendly_name": "My Company Line",'+
	'"phone_number": "+15105647903","voice_url": "http://mycompany.com/handleNewCall.php","voice_method": "POST","voice_fallback_url": null,"voice_fallback_method": "POST",'+
	'"voice_caller_id_lookup": null,"voice_application_sid": null,"date_created": "Mon, 16 Aug 2010 23:31:47 +0000","date_updated": "Mon, 16 Aug 2010 23:31:47 +0000",'+
	'"sms_url": null,"sms_method": "POST","sms_fallback_url": null,"sms_fallback_method": "GET","sms_application_sid": null,"capabilities": {"voice": null,"sms": null},'+
	'"status_callback": null,"status_callback_method": null,"api_version": "2010-04-01","uri": "/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/IncomingPhoneNumbers/PN2a0747eba6abf96b7e3c3ff0b4530f6e.json"}';
    	
    // register a mock Response with the Twilio_TestHTTPMock singleton service
	// for the HTTP GET method and at the Twilio Account instance URI.
	Twilio_TestHTTPMock.getInstance().putResponse(
		'POST',
		'https://api.twilio.com/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/IncomingPhoneNumbers.json',
		new Twilio_TestHTTPMock.Response(purchaseResponseBody,200)
		);
	TwilioIncomingPhoneNumber inNumber = phnumber0.purchase();
}

static testmethod void testTwilioIncomingPhoneNumbersList_get()
{
	String accountJsonResponseBody ='{"page": 0,"num_pages": 1,"page_size": 50,"total": 6,"start": 0,"end": 5,'+
	'"uri": "/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/IncomingPhoneNumbers.json",'+
	'"first_page_uri": "/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/IncomingPhoneNumbers.json?Page=0&PageSize=50",'+
	'"previous_page_uri": null,"next_page_uri": null,"last_page_uri": "/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/IncomingPhoneNumbers.json?Page=0&PageSize=50",'+
	'"incoming_phone_numbers": [{"sid": "PN3f94c94562ac88dccf16f8859a1a8b25","account_sid": "AC03c2fcd60e144e7cbeee413fcbf812a3","friendly_name": "Long Play",'+
	'"phone_number": "+14152374451","voice_url": "http://demo.twilio.com/long","voice_method": "GET","voice_fallback_url": null,"voice_fallback_method": null,'+
	'"voice_caller_id_lookup": null,"voice_application_sid": null,"date_created": "Thu, 13 Nov 2008 07:56:24 +0000","date_updated": "Thu, 13 Nov 2008 08:45:58 +0000",'+
	'"sms_url": null,"sms_method": null,"sms_fallback_url": null,"sms_fallback_method": null,"sms_application_sid": "AP9b2e38d8c592488c397fc871a82a74ec",'+
	'"capabilities": {"voice": true,"sms": false},"status_callback": null,"status_callback_method": null,"api_version": "2010-04-01",'+
	'"uri": "/2010-04-01/Accounts/ACdc5f1e11047ebd6fe7a55f120be3a900/IncomingPhoneNumbers/PN3f94c94562ac88dccf16f8859a1a8b25.json"}]}';
	
    // register a mock Response with the Twilio_TestHTTPMock singleton service
	// for the HTTP GET method and at the Twilio Account instance URI.
	Twilio_TestHTTPMock.getInstance().putResponse(
		'GET',
		'https://api.twilio.com/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/IncomingPhoneNumbers.json',
		new Twilio_TestHTTPMock.Response(accountJsonResponseBody,200)
		);
	 
	// Get an API client and request the Twilio Account
	TwilioRestClient client = new TwilioRestClient('AC03c2fcd60e144e7cbeee413fcbf812a3', authToken);
	TwilioIncomingPhoneNumberList twinnums=client.getAccount().getIncomingPhoneNumbers();
	
	System.assertNotEquals(null, twinnums);
	
	List<TwilioIncomingPhoneNumber> twinnumsList = twinnums.getPageData();
	
	System.assertNotEquals(null, twinnumsList);
	System.assertEquals(1, twinnumsList.size());
	System.assertEquals('PN3f94c94562ac88dccf16f8859a1a8b25', twinnumsList[0].getSid());
	System.assertEquals(Datetime.newInstanceGmt(2008,11,13,07,56,24),twinnumsList[0].getDateCreated());
	System.assertEquals(Datetime.newInstanceGmt(2008,11,13,08,45,58),twinnumsList[0].getDateUpdated());
	System.assertEquals('Long Play',twinnumsList[0].getFriendlyName());
	System.assertEquals('AC03c2fcd60e144e7cbeee413fcbf812a3',twinnumsList[0].getAccountSid());				
	System.assertEquals('+14152374451',twinnumsList[0].getPhoneNumber());
	System.assertEquals(null,twinnumsList[0].getVoiceApplicationSid());
	System.assertEquals('AP9b2e38d8c592488c397fc871a82a74ec',twinnumsList[0].getSmsApplicationSid());
	System.assertEquals('2010-04-01',twinnumsList[0].getApiVersion());
	System.assertEquals('http://demo.twilio.com/long',twinnumsList[0].getVoiceUrl());
	System.assertEquals('GET',twinnumsList[0].getVoiceMethod());
	System.assertEquals(null,twinnumsList[0].getVoiceFallbackurl());
	System.assertEquals(null,twinnumsList[0].getVoiceFallbackMethod());
	System.assertEquals(null,twinnumsList[0].getStatusCallback());
	System.assertEquals(null,twinnumsList[0].getStatusCallbackMethod()); 
	System.assertEquals(null,twinnumsList[0].getVoiceCallerIdLookup());
	System.assertEquals(null,twinnumsList[0].getSmsUrl());
	System.assertEquals(null,twinnumsList[0].getSmsMethod());
	System.assertEquals(null,twinnumsList[0].getSmsFallbackUrl());
	System.assertEquals(null,twinnumsList[0].getSmsFallbackMethod());		
	System.assertEquals(null,twinnumsList[0].getSmsStatusCallback());
	
	System.assertEquals(true,Boolean.valueof(twinnumsList[0].getcapabilities().get('voice')));
	System.assertEquals(false,Boolean.valueof(twinnumsList[0].getcapabilities().get('sms')));
	
	Iterator<TwilioIncomingPhoneNumber> it = twinnums.iterator();
    System.assertEquals(true, it.hasNext());
	
	TwilioIncomingPhoneNumber twinnum=it.next();
	System.assertEquals(false, it.hasNext());
	
}

static testmethod void testTwilioIncomingPhoneNumbers_create()
{
	String accountJsonResponseBody ='{"sid": "PN2a0747eba6abf96b7e3c3ff0b4530f6e","account_sid": "ACdc5f1e11047ebd6fe7a55f120be3a900","friendly_name": "My Company Line",'+

'"phone_number": "+15105647903","voice_url": "http://mycompany.com/handleNewCall.php","voice_method": "POST","voice_fallback_url": null,"voice_fallback_method": "POST",'+
'"voice_caller_id_lookup": null,"voice_application_sid": null,"date_created": "Mon, 16 Aug 2010 23:31:47 +0000","date_updated": "Mon, 16 Aug 2010 23:31:47 +0000",'+
'"sms_url": null,"sms_method": "POST","sms_fallback_url": null,"sms_fallback_method": "GET","sms_application_sid": null,"capabilities": {"voice": null,"sms": null},'+
'"status_callback": null,"status_callback_method": null,"api_version": "2010-04-01","uri": "/2010-04-01/Accounts/ACdc5f1e11047ebd6fe7a55f120be3a900/IncomingPhoneNumbers/PN2a0747eba6abf96b7e3c3ff0b4530f6e.json"}';

    // register a mock Response with the Twilio_TestHTTPMock singleton service
	// for the HTTP GET method and at the Twilio Account instance URI.
	Twilio_TestHTTPMock.getInstance().putResponse(
		'POST',
		'https://api.twilio.com/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/IncomingPhoneNumbers.json',
		new Twilio_TestHTTPMock.Response(accountJsonResponseBody,200)
		);
	
	
	map<string,string> p=new map<string,string>();
	p.put('PhoneNumber','+15105647903');
	p.put('FriendlyName','My Company Line');
	p.put('VoiceUrl','http://mycompany.com/handleNewCall.php');
	p.put('VoiceMethod','GET');
	
			
	
	// Get an API client and request the Twilio Account
	TwilioRestClient client = new TwilioRestClient('AC03c2fcd60e144e7cbeee413fcbf812a3', authToken);
	
	TwilioIncomingPhoneNumber twinnums= client.getAccount().getIncomingPhoneNumbers().create(p);
	
	System.assertEquals('PN2a0747eba6abf96b7e3c3ff0b4530f6e', twinnums.getSid());
	System.assertEquals(Datetime.newInstanceGmt(2010,08,16,23,31,47),twinnums.getDateCreated());
	System.assertEquals(Datetime.newInstanceGmt(2010,08,16,23,31,47),twinnums.getDateUpdated());
	System.assertEquals('My Company Line',twinnums.getFriendlyName());
	System.assertEquals('ACdc5f1e11047ebd6fe7a55f120be3a900',twinnums.getAccountSid());				
	System.assertEquals('+15105647903',twinnums.getPhoneNumber());
	System.assertEquals(null,twinnums.getVoiceApplicationSid());
	System.assertEquals(null,twinnums.getSmsApplicationSid());
	System.assertEquals('2010-04-01',twinnums.getApiVersion());
	System.assertEquals('http://mycompany.com/handleNewCall.php',twinnums.getVoiceUrl());
	System.assertEquals('POST',twinnums.getVoiceMethod());
	System.assertEquals(null,twinnums.getVoiceFallbackurl());
	System.assertEquals('POST',twinnums.getVoiceFallbackMethod());
	System.assertEquals(null,twinnums.getStatusCallback());
	System.assertEquals(null,twinnums.getStatusCallbackMethod()); 
	System.assertEquals(null,twinnums.getVoiceCallerIdLookup());
	System.assertEquals(null,twinnums.getSmsUrl());
	System.assertEquals('POST',twinnums.getSmsMethod());
	System.assertEquals(null,twinnums.getSmsFallbackUrl());
	System.assertEquals('GET',twinnums.getSmsFallbackMethod());		
	System.assertEquals(null,twinnums.getSmsStatusCallback());
	
}
static testmethod void testTwilioIncomingPhoneNumber_get()
{
	String accountJsonResponseBody ='{"sid": "PN2a0747eba6abf96b7e3c3ff0b4530f6e","account_sid": "ACdc5f1e11047ebd6fe7a55f120be3a900","friendly_name": "My Company Line",'+
	'"phone_number": "+15105647903","voice_url": "http://mycompany.com/handleNewCall.php","voice_method": "POST","voice_fallback_url": null,"voice_fallback_method": "POST",'+
	'"voice_caller_id_lookup": null,"voice_application_sid": null,"date_created": "Mon, 16 Aug 2010 23:31:47 +0000","date_updated": "Mon, 16 Aug 2010 23:31:47 +0000",'+
	'"sms_url": null,"sms_method": "POST","sms_fallback_url": null,"sms_fallback_method": "GET","sms_application_sid": null,"capabilities": {"voice": null,"sms": null},'+
	'"status_callback": null,"status_callback_method": null,"api_version": "2010-04-01","uri": "/2010-04-01/Accounts/ACdc5f1e11047ebd6fe7a55f120be3a900/IncomingPhoneNumbers/PN2a0747eba6abf96b7e3c3ff0b4530f6e.json"}';
    	
    Twilio_TestHTTPMock.getInstance().putResponse(
		'GET',
		'https://api.twilio.com/2010-04-01/Accounts/AC03c2fcd60e144e7cbeed179fcbf812a3/IncomingPhoneNumbers/PN3f94c94562ac88dccf16f8859a1a8b25.json',
		new Twilio_TestHTTPMock.Response(accountJsonResponseBody,200)
	);
	
	// Get an API client and request the Twilio Account
	TwilioRestClient client = new TwilioRestClient('AC03c2fcd60e144e7cbeed179fcbf812a3', authToken);
	
	TwilioIncomingPhoneNumber twinnums=client.getAccount().getIncomingPhoneNumber('PN3f94c94562ac88dccf16f8859a1a8b25');
	
	System.assertEquals('PN3f94c94562ac88dccf16f8859a1a8b25', twinnums.getSid());
	System.assertEquals('My Company Line',twinnums.getFriendlyName());
	System.assertEquals(Datetime.newInstanceGmt(2010,08,16,23,31,47),twinnums.getDateCreated());
	System.assertEquals(Datetime.newInstanceGmt(2010,08,16,23,31,47),twinnums.getDateUpdated());
	
	System.assertEquals('ACdc5f1e11047ebd6fe7a55f120be3a900',twinnums.getAccountSid());				
	System.assertEquals('+15105647903',twinnums.getPhoneNumber());
	System.assertEquals(null,twinnums.getVoiceApplicationSid());
	System.assertEquals(null,twinnums.getSmsApplicationSid());
	System.assertEquals('2010-04-01',twinnums.getApiVersion());
	System.assertEquals('http://mycompany.com/handleNewCall.php',twinnums.getVoiceUrl());
	System.assertEquals('POST',twinnums.getVoiceMethod());
	System.assertEquals(null,twinnums.getVoiceFallbackurl());
	System.assertEquals('POST',twinnums.getVoiceFallbackMethod());
	System.assertEquals(null,twinnums.getStatusCallback());
	System.assertEquals(null,twinnums.getStatusCallbackMethod()); 
	System.assertEquals(null,twinnums.getVoiceCallerIdLookup());
	System.assertEquals(null,twinnums.getSmsUrl());
	System.assertEquals('POST',twinnums.getSmsMethod());
	System.assertEquals(null,twinnums.getSmsFallbackUrl());
	System.assertEquals('GET',twinnums.getSmsFallbackMethod());		
	System.assertEquals(null,twinnums.getSmsStatusCallback());
}

static testmethod void testTwilioIncomingPhoneNumber_delete()
{
	String accountJsonResponseBody ='';
	Twilio_TestHTTPMock.getInstance().putResponse(
		'DELETE',
		'https://api.twilio.com/2010-04-01/Accounts/AC03c2fcd60e144e7cbeed179fcbf812a3/IncomingPhoneNumbers/PN3f94c94562ac88dccf16f8859a1a8b25.json',
		new Twilio_TestHTTPMock.Response(accountJsonResponseBody,200)
	);
	
	// Get an API client and request the Twilio Account
	TwilioRestClient client = new TwilioRestClient('AC03c2fcd60e144e7cbeed179fcbf812a3', authToken);
	
	boolean isdel=client.getAccount().getIncomingPhoneNumber('PN3f94c94562ac88dccf16f8859a1a8b25').deleteIncomingPhoneNumber();
	system.assert(true,isdel); 
	TwilioIncomingPhoneNumber twip=new TwilioIncomingPhoneNumber(client);
	TwilioIncomingPhoneNumberlist twipl=new TwilioIncomingPhoneNumberList(client);
}

static testmethod void testOutgoingCallerIDList_get()
{
	String accountJsonResponseBody ='{"outgoing_caller_ids":[{"sid":"PN17c8630939e44e7e92a45c51bcdb7122",'
	+'"account_sid":"AC03c2fcd60e144e7cbeee413fcbf812a3","friendly_name":"919902400323","phone_number":"+919902400323",'+
	'"date_created":"Thu, 29 Dec 2011 12:22:55 +0000","date_updated":"Thu, 29 Dec 2011 12:22:55 +0000",'+
	'"uri":"/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/OutgoingCallerIds/PN17c8630939e44e7e92a45c51bcdb7122.json"}],'+
	'"page":0,"num_pages":1,"page_size":50,"total":1,"start":0,"end":0,"uri":'+
	'"/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/OutgoingCallerIds.json","first_page_uri":"/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/OutgoingCallerIds'+
	'.json?Page=0&PageSize=50","previous_page_uri":null,"next_page_uri":null,"last_page_uri":"/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/OutgoingCallerIds.json?Page=0&PageSize=50"}';
    	
    // register a mock Response with the Twilio_TestHTTPMock singleton service
	// for the HTTP GET method and at the Twilio Account instance URI.
	Twilio_TestHTTPMock.getInstance().putResponse(
		'GET',
		'https://api.twilio.com/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/OutgoingCallerIds.json',
		new Twilio_TestHTTPMock.Response(accountJsonResponseBody,200)
		);
	
	// Get an API client and request the Twilio Account
	TwilioRestClient client = new TwilioRestClient('AC03c2fcd60e144e7cbeee413fcbf812a3', authToken);
	TwilioOutgoingCallerIdList twoutcallid=client.getAccount().getOutgoingCallerIds();
	System.assertNotEquals(null, twoutcallid);
	
	List<TwilioOutgoingCallerId> twocallidList = twoutcallid.getPageData();
	
	System.assertNotEquals(null, twocallidList);
	System.assertEquals(1, twocallidList.size());
	System.assertEquals('PN17c8630939e44e7e92a45c51bcdb7122', twocallidList[0].getSid());
	System.assertEquals(Datetime.newInstanceGmt(2011,12,29,12,22,55),twocallidList[0].getDateCreated());
	System.assertEquals(Datetime.newInstanceGmt(2011,12,29,12,22,55),twocallidList[0].getDateUpdated());
	System.assertEquals('919902400323',twocallidList[0].getFriendlyName());
	System.assertEquals('AC03c2fcd60e144e7cbeee413fcbf812a3',twocallidList[0].getAccountSid());
	System.assertEquals('+919902400323',twocallidList[0].getPhoneNumber());
	
	Twilio_TestHTTPMock.getInstance().putResponse(
		'GET',
		'https://api.twilio.com/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/OutgoingCallerIds.json?PhoneNumber=%2B919902400323',
		new Twilio_TestHTTPMock.Response(accountJsonResponseBody,200)
		);
	
	map<string,string> params=new map<String,string>();
	params.put('PhoneNumber','+919902400323');
	twoutcallid=client.getAccount().getOutgoingCallerIds(params);		
	Iterator<TwilioOutgoingCallerId> it = twoutcallid.iterator();
    System.assertEquals(true, it.hasNext());	
	TwilioOutgoingCallerId twocallid=it.next();
	
	System.assertEquals('PN17c8630939e44e7e92a45c51bcdb7122', twocallid.getSid());
	System.assertEquals(Datetime.newInstanceGmt(2011,12,29,12,22,55),twocallid.getDateCreated());
	System.assertEquals(Datetime.newInstanceGmt(2011,12,29,12,22,55),twocallid.getDateUpdated());
	System.assertEquals('919902400323',twocallid.getFriendlyName());
	System.assertEquals('AC03c2fcd60e144e7cbeee413fcbf812a3',twocallid.getAccountSid());
	System.assertEquals('+919902400323',twocallid.getPhoneNumber());
	System.assertEquals(false, it.hasNext());
}

static testmethod void testOutgoingCallerID_create()
{
	String accountJsonResponseBody ='{"account_sid":"AC03c2fcd60e144e7cbeee413fcbf812a3","phone_number":"+918722266012",'+
	'"friendly_name":"harsha","validation_code":844863}';
    	
    // register a mock Response with the Twilio_TestHTTPMock singleton service
	// for the HTTP GET method and at the Twilio Account instance URI.
	Twilio_TestHTTPMock.getInstance().putResponse(
		'POST',
		'https://api.twilio.com/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/OutgoingCallerIds.json',
		new Twilio_TestHTTPMock.Response(accountJsonResponseBody,200)
		);
	
	
	map<string,string> p=new map<string,string>();
	p.put('PhoneNumber','+9187222660');
	p.put('FriendlyName','harsha');
			
	
	// Get an API client and request the Twilio Account
	TwilioRestClient client = new TwilioRestClient('AC03c2fcd60e144e7cbeee413fcbf812a3', authToken);
	TwilioCallerIdValidation twoutcallid = client.getAccount().getOutgoingCallerIds().create(p);
	
	System.assertEquals('harsha',twoutcallid.getFriendlyName());
	System.assertEquals('AC03c2fcd60e144e7cbeee413fcbf812a3',twoutcallid.getAccountSid());
	System.assertEquals('+918722266012',twoutcallid.getPhoneNumber());
	System.assertEquals('844863',twoutcallid.getValidationCode());
	
}
static testmethod void testOutgoingCallerID_get()
{
	String accountJsonResponseBody ='{"sid":"PN17c8630939e44e7e92a45c51bcdb7122","account_sid":"AC03c2fcd60e144e7cbeee413fcbf812a3",'
	+'"friendly_name":"919902400323","phone_number":"+919902400323","date_created":"Thu, 29 Dec 2011 12:22:55 +0000","date_updated":'+
	'"Thu, 29 Dec 2011 12:22:55 +0000","uri":'+
	'"/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/OutgoingCallerIds/PN17c8630939e44e7e92a45c51bcdb7122.json"}';
    	
    // register a mock Response with the Twilio_TestHTTPMock singleton service
	// for the HTTP GET method and at the Twilio Account instance URI.
	Twilio_TestHTTPMock.getInstance().putResponse(
		'GET',
		'https://api.twilio.com/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/OutgoingCallerIds/PN17c8630939e44e7e92a45c51bcdb7122.json',
		new Twilio_TestHTTPMock.Response(accountJsonResponseBody,200)
		);
	
	// Get an API client and request the Twilio Account
	TwilioRestClient client = new TwilioRestClient('AC03c2fcd60e144e7cbeee413fcbf812a3', authToken);
	TwilioOutgoingCallerId twoutcallid=client.getAccount().getOutgoingCallerId('PN17c8630939e44e7e92a45c51bcdb7122');
	
	System.assertEquals('PN17c8630939e44e7e92a45c51bcdb7122', twoutcallid.getSid());
	System.assertEquals(Datetime.newInstanceGmt(2011,12,29,12,22,55),twoutcallid.getDateCreated());
	System.assertEquals(Datetime.newInstanceGmt(2011,12,29,12,22,55),twoutcallid.getDateUpdated());
	System.assertEquals('919902400323',twoutcallid.getFriendlyName());
	System.assertEquals('AC03c2fcd60e144e7cbeee413fcbf812a3',twoutcallid.getAccountSid());
	System.assertEquals('+919902400323',twoutcallid.getPhoneNumber());
	
	TwilioOutgoingCallerId  tci=new TwilioOutgoingCallerId(client); 
}

static testmethod void testOutgoingCallerID_delete()
{
	String accountJsonResponseBody ='';
    	
    // register a mock Response with the Twilio_TestHTTPMock singleton service
	// for the HTTP GET method and at the Twilio Account instance URI.
	Twilio_TestHTTPMock.getInstance().putResponse(
		'DELETE',
		'https://api.twilio.com/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/OutgoingCallerIds/PN17c8630939e44e7e92a45c51bcdb7122.json',
		new Twilio_TestHTTPMock.Response(accountJsonResponseBody,204)
		);
	
	// Get an API client and request the Twilio Account
	TwilioRestClient client = new TwilioRestClient('AC03c2fcd60e144e7cbeee413fcbf812a3', authToken);
	boolean isdel=client.getAccount().getOutgoingCallerId('PN17c8630939e44e7e92a45c51bcdb7122').deleteOutgoingCallerid();
	
	system.assertEquals(true,isdel); 
}

}`

TwilioAvailablePhoneNumber.cls
`/*
Copyright (c) 2012 Twilio, Inc.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
/
/
*

  • The Class AvailablePhoneNumber.

  • For more information see see http://www.twilio.com/docs/api/rest/available-phone-numbers
    */
    global class TwilioAvailablePhoneNumber extends TwilioResource.InstanceResource {

    /**

    • Instantiates a new available phone number.
    • @param client the client
      */
      public TwilioAvailablePhoneNumber(TwilioRestClient client) {
      super(client);
      }

    /**

    • Instantiates a new available phone number.
    • @param client the client
    • @param properties the properties
      */
      public TwilioAvailablePhoneNumber(TwilioRestClient client, Map<String, Object> properties) {
      super(client, properties);
      }

    public override String getResourceLocation() {
    throw new TwilioRestException('AvailablePhoneNumbers do not have an instance resource location');
    }

    /*

    • Property getters
      */

    /**

    • Gets the friendly name.
    • @return the friendly name
      */
      public String getFriendlyName() {
      return this.getProperty('friendly_name');
      }

    /**

    • Gets the phone number.
    • @return the phone number
      */
      public String getPhoneNumber() {
      return this.getProperty('phone_number');
      }

    /**

    • Gets the lata.
    • @return the lata
      */
      public String getLata() {
      return this.getProperty('lata');
      }

    /**

    • Gets the rate center.
    • @return the rate center
      */
      public String getRateCenter() {
      return this.getProperty('rate_center');
      }

    /**

    • Gets the latitude.
    • @return the latitude
      */
      public String getLatitude() {
      return this.getProperty('latitude');
      }

    /**

    • Gets the longitude.
    • @return the longitude
      */
      public String getLongitude() {
      return this.getProperty('longitude');
      }

    /**

    • Gets the region.
    • @return the region
      */
      public String getRegion() {
      return this.getProperty('region');
      }

    /**

    • Gets the postal code.
    • @return the postal code
      */
      public String getPostalCode() {
      return this.getProperty('postal_code');
      }

    /**

    • Gets the iso country.
    • @return the iso country
      */
      public String getIsoCountry() {
      return this.getProperty('iso_country');
      }

    /**

    • Gets the number capabilities.
    • @return the number capabilities
      */
      public map<string,object> getCapabilities() {
      return (Map<String,Object>)this.getObject('capabilities');
      }

    /**

    • Whether this number is new to the Twilio platform.
    • @return Beta status
      */
      public boolean getBeta() {
      return this.getPropertyBoolean('beta');
      }

    /**

    • Indicates whether this number requires an Address to be on file with Twilio.
    • Potential values are "any", "local", "foreign", or "none".
    • @return the address requirements
      */
      public String getAddressRequirements() {
      return this.getProperty('address_requirements');
      }

    /* Convenience Methods */

    private boolean purchased = false;

    public TwilioIncomingPhoneNumber purchase() {
    if (this.purchased) {
    throw new AlreadyPurchasedException('You have already purchased this number: '+getPhoneNumber());
    }
    Map<String,String> props = new Map<String,String>();
    props.put('PhoneNumber', getPhoneNumber());

     TwilioAccount requestAccount = ((TwilioRestClient)getClient()).getAccount(getRequestAccountSid());
     TwilioIncomingPhoneNumber incoming = requestAccount.getIncomingPhoneNumbers().create(props);
     this.purchased = true;
     return incoming;
    

    }

    private class AlreadyPurchasedException extends Exception {}
    }`

apex failure when trying the tutorial twilio-salesforce dialer

I opened a trial account and I'm trying to create a simple dialer with this tutorial

Thing is that first step of installing Twilio-Salesforce library (this url
is failing with

[Installing this package requires the following feature and its associated permissions: Apex Classes]
Apex Classes(classes/TwilioTRCapability.cls-meta.xml) Missing feature

triied to install to admins, to all users, nothing helps.
How exactly I install apex on a new trial salesforce env

Script thrown Exception error on TwilioRestException during deployment using changesets.

Description: When I try to deploy components to our production org using the changes I do have the components errors when try to validate the changeset.

Here is the error:
TwilioRestException: Script-thrown exception
Stack Trace: Class.TwilioRestClient: line 588, column 1
Class.TwilioResource: line 82, column 1
Class.TwilioResource.ListResource: line 463, column 1
Class.TwilioApplicationList: line 77, column 1 Class.Twilio_TestApplication.testTwilioAplications_filter: line 136, column 1

Screenshot:

image

Script-thrown Exception in TwilioSMS class

       Hi,

       Following is piece of my code. When this code is executed, I am getting Script-thrown exception. Any idea what could be wrong config/code here ? I am setting correct 'accountId' & 'authToken' value.



       private static TwilioSMS twilioSms;
       //Creating Twilio Client
        TwilioRestClient client = new TwilioRestClient(accountId, authToken);

        //Adding parameters to send in SMS
        Map<String,String> params = new Map<String,String>();
        params.put('To',phoneNumber);
        params.put('From',fromPhone);
        params.put('Body',textMessage);
        try{
            twilioSms = null;
            twilioSms = client.getAccount().getSMSMessages().create(params);
            System.debug(LoggingLevel.Error,'SMS Sent '+twilioSms);
        }catch(Exception e){
            String exceptionMessage = 'Exception Message: ' + e.getMessage();
            exceptionMessage += '\nTwilio Client Info: ' + client;
            exceptionMessage += '\nTwilio Params Passed: ' + params;
            System.debug(LoggingLevel.ERROR,'Error: '+ exceptionMessage);
            throw new SmsException(exceptionMessage);
        }

Call redirect is throwing exception 404 even though uri is valid

I have the following code running from developer console to redirect in progress calls to a conference room. Thought the URi of the call is valid the redirect is throwing 494 exception. Not sure why. Any help will be appreciated.

Here is my script.

TwilioRestClient client = TwilioAPI.getDefaultClient();
Map<String,String> filters = new Map<String,String>{'Status'=>'in-progress'};
Iterator calls = client.getAccount().getCalls(filters).iterator();
while (calls.hasNext()) {
TwilioCall call = calls.next();
System.Debug('Call Sid = ' + call.getSid());
System.Debug('Call Parent Sid = ' + call.getParentCallSid());
System.Debug('Call Uri = ' + call.getUri());

if(call.getParentCallSid() != null)    
call.redirect('http://test-businessfunding.cs10.force.com/conference',
        'POST'); 

}

Here is the error.

04:05:32:665 USER_DEBUG [8]|DEBUG|Call Uri = /2010-04-01/Accounts/AC5c27dcb4dd999d2aafc04c5d809d1483/Calls/CAde72b0c3dedadb4b9bc2f92405dbc1b6.json

04:05:32:720 USER_DEBUG [93]|DEBUG|RETURN: {code=20404, message=The requested resource /2010-04-01/Accounts/null/Calls/CAde72b0c3dedadb4b9bc2f92405dbc1b6.json was not found, more_info=https://www.twilio.com/docs/errors/20404, status=404}

One thing I noticed is that the resource has a null after account instead of the account SID. The uri for the call has real account SID. Not sure why.

Thanks

Need to improve unit test coverage

Classes with low coverage
TwilioMember - 69
TwilioMedia - 70
TwilioMediaList - 71
TwilioLookupRestClient - 52
TwilioClient - 71
TwilioCallerIdValidation - 73
TwilioTRWorkSpace - 75
TwilioQueue - 58
TwilioQueueList - 68
TwilioRecoeding - 74
TwilioAvailablePhoneNumber - 65
TwilioAPI - 70

Putting Client Softphone inbound call into a conference hangs up the call after 3 beeps.

I have the following code to transfer an inbound call to a browser soft phone from one agent to another agent. This code works well for transferring an outbound call from the same browser softphone to another phone. But for inbound calls the browser phone disconnects when it puts into a conference room.

Here is the code

    public void transferCall() {
        System.Debug('Phone Number = ' + callTo + ' Transfer Number = ' + transferTo);

        // Get the default Twilio Client
        TwilioRestClient client = TwilioAPI.getDefaultClient();
        Map<String,String> filters = new Map<String,String>{'Status'=>'in-progress'};
        Iterator<TwilioCall> calls = client.getAccount().getCalls(filters).iterator();
        System.Debug('Before Redirecting Calls to Conference');
        // Redirect the ongoing call to a conference room
        while (calls.hasNext()) {
            TwilioCall call = calls.next();
            System.Debug('Parent Call Sid = ' + call.getParentCallSid());
            System.Debug('Sid = ' + call.getSid());
            System.Debug('Call URI = ' + call.getUri());
            System.Debug('Call Status = ' + call.getStatus());
            System.Debug('Call Direction = ' + call.getDirection());
            if(((call.getDirection() == 'inbound' && call.getParentCallSid() != null) || 
               (call.getDirection() != 'inbound')) && (call.getStatus() == 'in-progress') 
              ){
                System.Debug('Before Re-directing call to conference Call URI = ' + call.getUri()); 
                call.redirect('http://test-businessfunding.cs10.force.com/conference', 'POST');
                System.Debug('After Re-directing call to conference Call URI = ' + call.getUri());
            }
        }
        System.Debug('After Redirecting Calls to Conference');

        // Dial the transfer number to join the conference room
        Map<String,String> params = new Map<String,String>{
            'To' => transferTo,
            'From' => TwilioAPI.getTwilioConfig().CallerId__c,
            'Url' => 'http://test-businessfunding.cs10.force.com/conference'
        };
        System.Debug('Before Making new call to Transfer number to join the same conference');
        TwilioCall call = client.getAccount().getCalls().create(params);
        System.Debug('After Making new call to Transfer number to join the same conference');
        System.debug(call.getDuration());
        System.debug(call.getSid());             
    } 

Any help in resolving this critical issue will be highly appreciated.

Thanks

ant deployment failure

Hi, I'm getting the following errors when I try to deploy to a dev org using ANT:

All Test Failures:

  1. Twilio_TestApplication.testTwilioAplications_filter -- TwilioRestException:
    Script-thrown exception
    Stack trace: Class.TwilioRestClient: line 591, column 1
    Class.TwilioResource: line 82, column 1
    Class.TwilioResource.ListResource: line 463, column 1
    Class.TwilioApplicationList: line 80, column 1
    Class.Twilio_TestApplication.testTwilioAplications_filter: line 139, column
    1
  2. Twilio_TestPhoneNumbers.testTwilioAvailablePhoneNumbers_AreaCodeFilter -- Tw
    ilioRestException: Script-thrown exception
    Stack trace: Class.TwilioRestClient: line 591, column 1
    Class.TwilioResource: line 82, column 1
    Class.TwilioResource.ListResource: line 463, column 1
    Class.TwilioAvailablePhoneNumberList: line 106, column 1
    Class.Twilio_TestPhoneNumbers.testTwilioAvailablePhoneNumbers_AreaCodeFilter
    : line 274, column 1
  3. TwilioCapability.testGenerateParamString -- System.AssertException: Assertio
    n Failed: Expected: cat=dog&foo=bar, Actual: foo=bar&cat=dog
    Stack trace: Class.TwilioCapability.testGenerateParamString: line 273, colum
    n 1

I have traced the error by running just the Twilio_TestPhoneNumbers.testTwilioAvailablePhoneNumbers_AreaCodeFilter method. What I found is the following message:

"Did not find Resource for GET https://api.twilio.com/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/AvailablePhoneNumbers/US/Local.json"

And that's because the uri passed to the Twilio_TestHTTPMock Reponse is not contained in the resourceMap.keySet();

Params:
(uri:)HTTPS://API.TWILIO.COM/2010-04-01/ACCOUNTS/ACBA8BC05EACF94AFDAE398E642C9CC32D/AVAILABLEPHONENUMBERS/US/LOCAL.JSON

(resourceMap().keySet()) Keys :{HTTPS://API.TWILIO.COM/2010-04-01/ACCOUNTS/ACBA8BC05EACF94AFDAE398E642C9CC32D/AVAILABLEPHONENUMBERS/US/LOCAL.JSON?AREACODE=510&CONTAINS=51034*****

Need help!

TwilioConfig object not deploying on "installation"

Hey guys,

I've got a fresh DE sandbox set up and the ant task deploys everything except the custom object. I've hardcoded the object name into the package.xml but still nada. There aren't any logs that give me more info so I'm hoping you can help :)

ant deployTwilio failure "The Apex job named "EventBrite Data Pulling Scheduler" is already scheduled for execution"

On Mac OSX 10.8.4
ant 1.8.4

$ ant deployTwilio
Buildfile: /Users/myname/twilio-salesforce/install/build.xml

deployTwilio:
[echo] Deploying Twilio Helper Library for Salesforce...
[sf:deploy] Request for a deploy submitted successfully.
[sf:deploy] Request Id for the current deploy task: 09Sa0000000Cso2EAC
[sf:deploy] Waiting for server to finish processing the request...
[sf:deploy] Request Status: InProgress
[sf:deploy] Request Status: InProgress
[sf:deploy] Request Status: InProgress
[sf:deploy] Request Status: InProgress
[sf:deploy] Request Status: InProgress-Running Test: AddAccountTest.testSave1
[sf:deploy] Request Status: InProgress-Running Test: CoachBreakdownCalculator.testProductRemoval
[sf:deploy] Request Status: InProgress-Running Test: EventRegistrationController.testBadEmail
[sf:deploy] Request Status: InProgress-Running Test: OrderEntry7Extension.testAccountCreation
[sf:deploy] Request Status: InProgress-Running Test: ScheduleBatchConvertIndividualAccounts.testBatchConvertIndividualAccounts
[sf:deploy] Request Status: Completed

BUILD FAILED
/Users/myname/twilio-salesforce/install/build.xml:9: FAILURES:
Test failure, method: EventBriteJobScheduler.testBatchConvertIndividualAccounts -- System.AsyncException: The Apex job named "EventBrite Data Pulling Scheduler" is already scheduled for execution. stack Class.EventBriteJobScheduler.execute: line 7, column 1

Test failure, method: OrderEntry7Extension.testLeadConversion -- System.AssertException: Assertion Failed stack Class.OrderEntry7Extension.testLeadConversion: line 590, column 1

Test failure, method: ParseProductTest.testBatchConvertIndividualAccounts -- System.AsyncException: The Apex job named "EventBrite Data Pulling Scheduler" is already scheduled for execution. stack Class.EventBriteJobScheduler.execute: line 7, column 1

Test failure, method: TwilioCapability.testGenerateParamString -- System.AssertException: Assertion Failed: Expected: split%2Bkey2=split%2Bval2&split+key1=split+val1, Actual: split+key1=split+val1&split%2Bkey2=split%2Bval2 stack Class.TwilioCapability.testGenerateParamString: line 275, column 1

Total time: 1 minute 48 seconds

Exception: Script-thrown exception

Hi I get Exception: Script-thrown exception. See code below:

trigger SendSMS on LCR__c (after update)
{
for (LCR__c lcr : Trigger.new)
{
SMSwithTwilio.SendSMS();
}
}

public class SMSwithTwilio
{
@future (callout=true)
public static void SendSMS()
{
String ACCOUNT_SID = 'xxx';
String AUTH_TOKEN = 'xxx';
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    Map<String,String> properties = new Map<String,String> 
    {
        'To'   => '+1408xxxx',
        'From' => '+1408xxx',
        'Body' => 'Hello!'
    };
    TwilioSMS message = client.getAccount().getSmsMessages().create(properties);

}
}

ant deployTwilio fails

Hello: I cloned twilio locally and entered my username and password, however, when i run ant deployTwilio, i get the following error:

Buildfile: /Users/ssharaf/development/twilio-twilio-salesforce-f2af6e6/install/build.xml

deployTwilio:
[echo] Deploying Twilio Helper Library for Salesforce...

BUILD FAILED
/Users/ssharaf/development/twilio-twilio-salesforce-f2af6e6/install/build.xml:9: Problem: failed to create task or type antlib:com.salesforce:deploy
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
No types or tasks have been defined in this namespace yet

This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-/usr/share/ant/lib
-/Users/ssharaf/.ant/lib
-a directory added on the command line with the -lib argument

Total time: 0 seconds

thanks
Sam

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.