Backbone / JS:希望通过AJAX调用访问Twilio SMS API [英] Backbone/JS: looking to access the Twilio SMS API via an AJAX call

查看:266
本文介绍了Backbone / JS:希望通过AJAX调用访问Twilio SMS API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要设置Twilio的SMS服务,以便当用户按下某个按钮时,它利用我的帐户与Twilio发送文本。

Looking to set up Twilio's SMS service so that when a user presses a certain button, it leverages my account with Twilio to send a text.

使用Backbone.js和coffeescript,这必须在客户端执行,所以我做这样的事情:

Using Backbone.js with coffeescript, and this has to be done client-side for the moment, so I'm doing something like this:

events: {
        "click .button": "sendText"
}

那么 sendText 看起来像这样:

sendText: ()->
    accountSid = '{my account sid}'
    authToken = '{my auth token}'
    ToNumber = "{string of a number to text to}"
    FromNumber = "{string of my Twilio number}"
    Body = escape("Hey, this is working.")

    myJSONData = "To=%2B1" + ToNumber + ", From=%2B1" + FromNumber + ", Body=" + Body

    $.ajax({
                type: 'POST',
                url: 'https://api.twilio.com/2010-04-01/Accounts/'+ accountSid + '/SMS/Messages',
                data: myJSONData,
                success: (data) -> {
                    console.log('SMS sent successfully!')
                }
        })

正确的方向?我知道我没有在任何地方输入我的验证凭证,但我不知道该怎么做。

Is this heading in the right direction? I know that I haven't entered my auth credentials anywhere yet, but I'm not certain where to do that yet.

推荐答案

在任何情况下,您都不应该有任何想要查看源代码的用户拥有您的authToken(情况更糟糕,因为您还包括您的帐户sid)。

You shouldn't, under any circumstance, have your authToken (and the situation is worse as you're also including your account sid) available for anyone who wants to see you source code.

有了这些信息,我可以代表您提供数字,拨打电话,返回号码...您只是不能在客户端执行此操作。

With that info, I can provision numbers on your behalf, make calls, return numbers... You just can't do it on the client side.

您应该连接(使用Ajax如果你想)到您的服务器,这反过来将连接到twilio传递您的凭证。这样,唯一知道他们的人就是您的服务器。

You should connect (using Ajax if you want) to your server, which in turn would connect to twilio passing your credentials. That way, the only one who knows them is your server.

这篇关于Backbone / JS:希望通过AJAX调用访问Twilio SMS API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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