如何使用Google脚本和Google电子表格发送短信(短信) [英] How to Use Google Script with Google Spreadsheet to send SMS (Text) Messages

查看:198
本文介绍了如何使用Google脚本和Google电子表格发送短信(短信)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此Google脚本页面表示,stackoverflow是发布Google脚本问题,所以在这里。



我想使用Google脚本自动发送短信(SMS)到Google Spreadsheet中的所有手机号码。

可以通过以下电子邮件向电子表格中的所有电子邮件地址发送电子邮件:本教程,但是当我尝试在电子表格中使用电话号码代替电子邮件地址时,出现一个错误消息,那些电子邮件地址无效。很公平。如果我知道与这些手机号码绑定的手机公司,我可以将这些电话号码转换为电子邮件地址(一些常见的选项,有几位指南解释它, like this )但是我没有那个手机提供商的信息。



我当然不是第一个尝试从电脑而不是手机发送短信的人。 这个问题是一个比较受欢迎(但也是较老)的问题。 Twilio 弹出几个我已经看过的答案,但这不是免费服务(尽管这是相当便宜的,我承认)谷歌有免费选择,所以我想我会尝试这些。 Google语音可以发送免费短信,您甚至可以发送免费短信通过Gmail



I知道很多人都搜索API以使用Google服务发送短信似乎没有一个。有一些有趣的项目,如 google-voice-java ,但这些更多所以我想我只是使用一个Google服务(一个Google文档电子表格)通过使用另一个(Google Voice或GMail)来调用另一个(Google Voice或GMail)。

第三(Google脚本)。有没有办法做到这一点?有没有办法让Google脚本发送短信?例如, MailApp.sendEmail 发送电子邮件 - 是否有一个用于发送短信(SMS)?如果没有,可以按邮件发送电子邮件发送文本(无需将电话号码转换为电子邮件地址,例如[电话号码] @ txt.att 。净)?是否可以使用其他一些脚本选项,可能与Google聊天有关(因为GMail短信选项与Google Chat有关)? >我最近成为一个团队的一员,他们制作了一个名为文本gBlaster 完成我相信你所要求的。如果你想自己做,而不需要通过运营商的电子邮件服务发送它(比尔(比尔)以上提到,这是一个很好的解决方案),那么你将需要使用像Twilio这样的第三方(这是我们正在使用的人)。您基本上使用电子表格将请求发送给Twilio,然后Twilio发送消息。

以下是您可以在Twilio上使用的一些基本代码,只要您遵循该路线。您需要定义toNumber,bodyMessage,SID,Token和twilioNumber。 toNumber是接收消息的号码,bodyMessage是文本消息的主体,SID&当您创建Twilio帐户时,会为您提供令牌,twilioNumber是您通过Twilio通过邮件发送的电话号码。

  function sendSms(toNumber,bodyMessage,SID,Token,twilioNumber){
var url =https://api.twilio.com/2010-04-01/Accounts/+ // URL用于输入正确的Twilio acct
SID +/SMS/Messages.json;
var options = {//指定消息的类型
方法:post,//发送而不是Get,因为我们发送
头文件:{
授权:Basic +
Utilities.base64Encode(SID +:+令牌)
},
有效载荷:{// SMS详情
来自:twilioNumber,
To:toNumber,
Body:bodyMessage
}
};
var response = UrlFetchApp.fetch(url,options); //调用行动
Logger.log(response);
}


This Google Script page says that stackoverflow is the place to post Google Script questions, so here I am.

I want to use a Google Script to automatically send text messages (SMS) to all cell phone numbers in a Google Spreadsheet.

It is possible to send e-mails to all e-mail addresses in a spreadsheet by following this tutorial but when I try using phone numbers in a spreadsheet in place of e-mail addresses I get an error that those are not valid e-mail addresses. Fair enough. If I knew the cell phone companies tied to each of those cell phone numbers I could convert those phone numbers into e-mail addresses (a common option with several guides explaining it, like this one) but I don't have that cell phone provider information.

I am certainly not the first person to try to automatically send text messages from a computer rather than a cell phone. This question is one of the more popular (but also older) questions asking about it. Twilio pops up in several answers I've looked through but that is not a free service (although it is pretty inexpensive, I will admit.) Google has free options, though, so I figured I'd try those. Google Voice can send free text messages and you can even send free text messages through Gmail.

I know that many have searched for an API to use Google services to send text messages and there doesn't seem to be one. There are some interesting projects like google-voice-java but these are more work arounds than anything.

Thus I figured I'd just use one Google service (a Google Docs spreadsheet) to call another (Google Voice or GMail) through the use of a 3rd (Google Script). Is there some way to do this? Is there a way to get a Google Script to send text messages? For example, the MailApp.sendEmail sends e-mails - is there one to send text messages (SMS)? If not, can MailApp.sendEmail be massaged/jury rigged to send texts (without needing to turn the phone number into an e-mail address like [phonenumber]@txt.att.net)? Could some other scripting option be used, perhaps related to Google Chat (since the GMail texting option is related to Google Chat)?

解决方案

I was recently part of a team that produced a Google add-on named Text gBlaster that accomplishes what I believe you are asking for. It makes like easy so feel free to give it a try.

Aside from that, if you want to do it yourself without it sending via the carrier's email service (that Bill mentions above, which is a fine solution) then you will need to use a third party like Twilio (which is who we are using). You basically use the spreadsheet to send the request to Twilio and then Twilio sends the messages out.

Here is some basic code you can use with Twilio if you go that route. You will need to define toNumber, bodyMessage, SID, Token, and twilioNumber. toNumber is the number that is receiving the message, bodyMessage is the body of the text message, SID & Token are provided to you when you create a Twilio account, and twilioNumber is the phone number that you have through Twilio that the message will be sent from.

    function sendSms(toNumber,bodyMessage, SID, Token, twilioNumber) {
    var url = "https://api.twilio.com/2010-04-01/Accounts/" +            // URL used to enter correct Twilio acct
      SID + "/SMS/Messages.json";                                           
    var options = {                                                      // Specify type of message             
      method: "post",                                                    // Post rather than Get since we are sending
      headers: {                                                         
        Authorization: "Basic " + 
        Utilities.base64Encode(SID + ":" + Token)
      },
      payload: {                                                         // SMS details
        From: twilioNumber,
        To: toNumber,
        Body: bodyMessage
      }
    };
    var response = UrlFetchApp.fetch(url, options);                   // Invokes the action
    Logger.log(response);
}

这篇关于如何使用Google脚本和Google电子表格发送短信(短信)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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