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

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

问题描述

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

  • 您能否通过 Postman 之类的内容发布到该网址?你应该如果你传入一些 JSON,至少会得到一个错误......
  • 该消息是否已发送至 SF 并在那里失败,或从未发送,这表明 SFDC 中的 URL/REST 类存在问题
  • 检查 Twilio SMS 日志 - 您应该会在 SMS 日志中看到结果错误代码的成功或失败.
  • 您是否在 SF 的 Cusom 设置中设置了 Twilio 信用?它使用它们进行签名检查.
  • SFDC 调试日志向您展示了什么?您可以查看站点用户的调试日志如果您在 Monitor - Debug 中设置它并搜索站点用户.
  • 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天全站免登陆