Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RestResource(urlMapping='/textlead/*')
- global with sharing class TextLeadRestfulReceiver {
- @HttpGet
- global static String init() {
- String payload = ' -d "grant_type=password"' +
- ' -d "client_id=ID"' +
- ' -d "client_secret=secret"' +
- ' -d "username=here@there.com.staging"' +
- ' -d "password=whateverTOKEN"';
- HttpRequest req = new HttpRequest();
- req.setMethod('GET');
- req.setEndpoint('https://login.salesforce.com/services/oauth2/token');
- req.setHeader('Content-Type','application/x-www-form-urlencoded');
- req.setHeader('Content-Length', String.valueOf(payload.length()));
- req.setHeader('X-PrettyPrint', '1');
- req.setBody(payload);
- Http binding = new Http();
- HttpResponse res = binding.send(req);
- System.debug(String.valueOf(res));
- return String.valueOf(res);
- }
- global static String saveText() {
- String ACCOUNT_SID = 'what';
- String AUTH_TOKEN = 'ever';
- TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
- RestRequest request = RestContext.request;
- request.addHeader('Authorization', 'Bearer');
- String body = 'Nada.';
- String leadNumber = request.requestURI.substring(request.requestURI.lastIndexOf('/') + 1);
- List<Lead> result = [SELECT Id, FirstName, MobilePhone
- FROM Lead WHERE MobilePhone=:leadNumber];
- for (TwilioMessage message: client.getAccount().getMessages().getPageData()) {
- body = message.getBody();
- }
- for (Lead l: result) {
- Task task = new Task(WhoId = l.Id, OwnerId = l.OwnerId, Description = body, ActivityDate = Date.today(),
- Subject = 'Text received from ' + l.FirstName + ' on ' + leadNumber);
- insert task;
- }
- return body;
- }
- }
- String ACCOUNT_SID = 'AXXXXXXXXXXXXXXXXX';
- String AUTH_TOKEN = 'YYYYYYYYYYYYYYYYYY';
- TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
- for (TwilioSms message : client.getAccount().getSmsMessages().getPageData()) {
- System.debug(message.getBody());
- }
- @RestResource(urlMapping = '/textlead/')
- global with sharing class TextLeadReceiver {
- @HttpGet
- global static String TextLeadReceiver() {
- RestRequest req = RestContext.request;
- RestResponse res = RestContext.response;
- String ACCOUNT_SID = 'what';
- String AUTH_TOKEN = 'ever';
- TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
- String subject = 'Text received from {0} on {1}';
- String phone = 'No phone';
- String body = 'Nada.';
- req.addHeader('Accept', 'application/json');
- try {
- for (TwilioMessage message: client.getAccount().getMessages().getPageData()) {
- body = message.getBody();
- phone = message.getFrom();
- System.debug('SMS body: ' + body);
- System.debug('SMS phone: ' + phone);
- }
- List<Lead> leads = [SELECT Id, FirstName, MobilePhone, Phone, Phone_2__c
- FROM Lead WHERE MobilePhone = :phone
- OR Phone = :phone OR Phone_2__c = :phone];
- for (Lead l: leads) {
- List<String> args = new List<String>(new String[] { l.FirstName, phone });
- String newSubject = String.format(subject, args);
- Task task = new Task(WhoId = l.Id, OwnerId = l.OwnerId, Description = body,
- ActivityDate = Date.today(), Subject = newSubject);
- insert task;
- }
- System.debug('SMS saved: ' + body);
- } catch(System.CalloutException e) {
- System.debug('SMS error: ' + e);
- }
- return body;
- }
- }
- @RestResource(urlMapping = '/textlead/')
- global with sharing class TextLeadReceiver {
- @HttpGet
- global static String TextLeadReceiver() {
- Public with sharing class TextLeadReceiver {
- Public String TextLeadReceiver() {
- ApexPages.currentPage().getParameters().get('paramName');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement