如何通过twilio获取短信请求 [英] How to get SMS request via twilio

查看:223
本文介绍了如何通过twilio获取短信请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以访问salesforce中站点URL的类. 网站网址".twilioSMS网址Twilio帐户的SMS网址和salesforce网站的网址现在是相同的.每当通过twilio发送SMS时,都会在沙箱中自动创建Case.但是这里没有发生.我做的是正确的生产者吗?有人请帮助我.如何解决此问题.我已经检查了twilio短信网址,例如" https://somesalesforce.com/service/apexrest/smsToApex ".我将同时提供Salesforce网站URL和Twilio SMS URL的URL.

I have a class that can access the site url in the salesforce. The site url ".The twilio SMS url correct are not how to check?The Twilio account SMS url and salesforce site url are same as of now.Whenever SMS is came via twilio then automatically Case is createin the sandbox.But here not happened.I doing correct producer are not?.Can someone please help me.How to resolve this problem.I have checked the twilio sms url like this "https://somesalesforce.com/service/apexrest/smsToApex".which url I will give both Salesforce site url, Twilio SMS url.

@RestResource(urlMapping='/smsToApex')
global class smsToApex 
{   
    Static TwilioAccount account = TwilioAPI.getDefaultAccount();         
    @HttpPost
    global static void incomingSMS() 
    {        
        // This will error out with System.LimitException if we would exceed
        // our daily email limit
        Messaging.reserveSingleEmailCapacity(1);

        String expectedSignature = RestContext.request.headers.get('X-Twilio-Signature');
        system.debug('ES' + expectedSignature);
        String url = 'https://' + RestContext.request.headers.get('Host') + '/services/apexrest' + RestContext.request.requestURI;
        Map <String, String> params = RestContext.request.params;
       system.debug('smsToApex========>'+params);
        // Validate signature
        if (!TwilioAPI.getDefaultClient().validateRequest(expectedSignature, url, params)) {
            RestContext.response.statusCode = 403;
            RestContext.response.responseBody = Blob.valueOf('Failure! Rcvd '+expectedSignature+'\nURL '+url/*+'\nHeaders'+RestContext.request.headers*/);

            return;
        }       
        RestContext.response.responseBody = Blob.valueOf('ok');        
        String caseFrom = params.get('From');
         String caseTo = params.get('To');
        String   caseBody = params.get('Body');          
          System.debug('Step 4 smsToApex caseFrom==>'+caseFrom);
          System.debug('Step 5 smsToApex caseTo===>'+caseTo);
          System.debug('Step 6 smsToApex caseBody===>'+caseBody);          
           Case ca = new Case();
            ca.Subject = 'Test smsToApex caseFrom'+caseFrom;
            ca.Description = 'Test smsToApex caseBody'+caseBody+','+caseTo;
            ca.Origin = 'Phone';
            INSERT ca;                  
     }                       
}

推荐答案

要检查的几件事...

A few things to check...

  • 您能否通过邮递员?你应该 如果传递一些JSON,至少会得到一个错误...
  • 该消息是发送到SF还是失败,或者从不发送,这表明SFDC中的URL/REST类有问题
  • 检查Twilio SMS日志-您应该在SMS日志中看到结果 错误代码是成功还是失败.
  • 您是否在SF的Cusom设置中设置了Twilio凭据?它使用它们进行签名检查.
  • SFDC调试日志向您显示什么?您可以查看站点用户的调试日志 如果您在监视器-调试"中进行设置,然后搜索站点用户".
  • Can you post to that URL via something like Postman? You should at least get an error if you pass in some JSON...
  • Is the message making it to SF and failing there, or never making it, which would indicate a problem with the URL/REST Class in SFDC
  • Check the Twilio SMS logs - you should see the result in the SMS logs either success or failure with the error code.
  • Did you set the Twilio creds in the Cusom Setting in SF? It uses them for the signature check.
  • What do the SFDC debug logs show you? You can view the debug logs for a Sites user if you set it up in Monitor - Debug and search for the Site User.

这篇关于如何通过twilio获取短信请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆