本文及资源最后更新时间 2021-08-27 by sky995
谷歌语音产品 Google Voice 如果很久没有使用,那么谷歌 Google 会根据其协议“如果您已经很久没有使用语音号码,您将收到语音号码将从帐户中删除的警告。您还将看到回收日期,即号码将被删除的日期。“所以以往我们都是每隔一两个月发一条信息来维持账号的存在,俗称 Google Voice 保号。
Google Voice 自动回复
登入 Google Voice,先在 Google Voice 右上角设置里面把将消息转发到电子邮件
打开。
登入与 Google Voice 同一账号的 Google Gmail(右上角直接切换过去即可),依次打开右上角设置
→查看所有设置
,在设置里选择过滤器和屏蔽的地址
→创建新的过滤器
在发件人处填写@txt.voice.google.com
如下图所示:
发件人填写好后,点击创建过滤器
。在弹出的对话框点击选择标签
→新建标签
,输入标签名为“autoreply
”,点击创建即可。
这里缙哥哥建议勾选跳过收件箱(将其归档)
,应用标签在你创建后会自动勾选。
登录 Google Drive(右上角直接切换到谷歌云端硬盘),单击左上角那个大大的新建
按钮。按下图新建一个 Google App Script(如未找到可以在关联更多应用
里面查找 Google Apps Script 关联一下就有了)。
复制下面的代码替换现有的代码。
<code> <span class="kwd">function</span><span class="pln"> autoReplier</span><span class="pun">()</span> <span class="pun">{</span> <span class="kwd">var</span><span class="pln"> labelObj </span><span class="pun">=</span> <span class="typ">GmailApp</span><span class="pun">.</span><span class="pln">getUserLabelByName</span><span class="pun">(</span><span class="str">'autoreply'</span><span class="pun">);</span> <span class="kwd">var</span><span class="pln"> gmailThreads</span><span class="pun">;</span> <span class="kwd">var</span><span class="pln"> messages</span><span class="pun">;</span> <span class="kwd">var</span><span class="pln"> messagecount</span><span class="pun">;</span> <span class="kwd">var</span><span class="pln"> sender</span><span class="pun">;</span> <span class="kwd">var</span><span class="pln"> num </span><span class="pun">=</span> <span class="lit">6</span><span class="pun">;</span> <span class="com">//设置连续自动回复邮件的次数(为防止两人都是自动回复,当发送次数达到 6 时将不自动回复)。</span> <span class="kwd">var</span><span class="pln"> hours </span><span class="pun">=</span> <span class="lit">12</span><span class="pun">;</span> <span class="com">//过了多少小时后又可以自动回复。</span> <span class="kwd">try</span> <span class="pun">{</span> <span class="kwd">for</span> <span class="pun">(</span><span class="kwd">var</span><span class="pln"> gg </span><span class="pun">=</span> <span class="lit">0</span><span class="pun">;</span><span class="pln"> gg </span><span class="pun"><</span><span class="pln"> labelObj</span><span class="pun">.</span><span class="pln">getUnreadCount</span><span class="pun">();</span><span class="pln"> gg</span><span class="pun">++)</span> <span class="pun">{</span><span class="pln"> gmailThreads </span><span class="pun">=</span><span class="pln"> labelObj</span><span class="pun">.</span><span class="pln">getThreads</span><span class="pun">()[</span><span class="pln">gg</span><span class="pun">];</span><span class="pln"> messages </span><span class="pun">=</span><span class="pln"> gmailThreads</span><span class="pun">.</span><span class="pln">getMessages</span><span class="pun">();</span><span class="pln"> messagecount </span><span class="pun">=</span><span class="pln"> gmailThreads</span><span class="pun">.</span><span class="pln">getMessageCount</span><span class="pun">();</span> <span class="com">//console.log(messages[messagecount - 9].getDate() + " time");</span> <span class="kwd">for</span> <span class="pun">(</span><span class="kwd">var</span><span class="pln"> ii </span><span class="pun">=</span> <span class="lit">0</span><span class="pun">;</span><span class="pln"> ii </span><span class="pun"><</span><span class="pln"> messages</span><span class="pun">.</span><span class="pln">length</span><span class="pun">;</span><span class="pln"> ii</span><span class="pun">++)</span> <span class="pun">{</span> <span class="kwd">if</span> <span class="pun">(</span><span class="pln">messages</span><span class="pun">[</span><span class="pln">ii</span><span class="pun">].</span><span class="pln">isUnread</span><span class="pun">())</span> <span class="pun">{</span><span class="pln"> msg </span><span class="pun">=</span><span class="pln"> messages</span><span class="pun">[</span><span class="pln">ii</span><span class="pun">].</span><span class="pln">getPlainBody</span><span class="pun">();</span><span class="pln"> sender </span><span class="pun">=</span><span class="pln"> messages</span><span class="pun">[</span><span class="pln">ii</span><span class="pun">].</span><span class="pln">getFrom</span><span class="pun">();</span><span class="pln"> array </span><span class="pun">=</span> <span class="pun">[[</span><span class="str">"天之道,损有余而补不足。——《道德经》"</span><span class="pun">],[</span><span class="str">"四月为乾,生气在卯,死气在酉,不宜用巳日时,犯月建,百事不吉。——《摄生月令》"</span><span class="pun">],[</span><span class="str">"喜怒伤性,哀乐伤神。伤性则害生,伤神则侵命。故养性以全气,保神以安心。气完则体平,心安则神逸,此全生至要诀也。——《太玄经》"</span><span class="pun">],[</span><span class="str">"阳常有余,阴常不足。——《局方发挥》"</span><span class="pun">],[</span><span class="str">"阴阳者,天地之道也,万物之纲纪,变化之父母,生杀之本始,神明之府也,治病必求于本。——《素问》"</span><span class="pun">],[</span><span class="str">"阴阳平,则天地和而人气宁;阴阳逆,则天地否而人气厥。——《华氏中藏经》"</span><span class="pun">],[</span><span class="str">"证有阴阳,脉有阴阳,药有阴阳。——《景岳全书》"</span><span class="pun">],[</span><span class="str">"天有四时五行,以生长收藏,以生寒暑燥湿风。人有五藏,化五气,以生喜怒悲忧恐。——《素问》"</span><span class="pun">],[</span><span class="str">"善用兵者,必先屯粮;善治邪者,必先养正。——《经历杂论》"</span><span class="pun">]];</span> <span class="kwd">var</span><span class="pln"> j </span><span class="pun">=</span> <span class="typ">Math</span><span class="pun">.</span><span class="pln">floor</span><span class="pun">(</span><span class="typ">Math</span><span class="pun">.</span><span class="pln">random</span><span class="pun">()</span> <span class="pun">*</span> <span class="pun">(</span><span class="pln">array</span><span class="pun">.</span><span class="pln">length</span><span class="pun">));</span> <span class="kwd">var</span><span class="pln"> temp </span><span class="pun">=</span><span class="pln"> array</span><span class="pun">[</span><span class="pln">j</span><span class="pun">];</span> <span class="kwd">if</span> <span class="pun">(</span><span class="pln">messagecount </span><span class="pun"><</span><span class="pln"> num</span><span class="pun">){</span> <span class="typ">MailApp</span><span class="pun">.</span><span class="pln">sendEmail</span><span class="pun">(</span><span class="pln">sender</span><span class="pun">,</span> <span class="str">"Auto Reply"</span><span class="pun">,</span><span class="pln"> temp</span><span class="pun">);</span> <span class="pun">}</span><span class="kwd">else</span> <span class="kwd">if</span><span class="pun">(</span> <span class="pun">(</span><span class="pln">messages</span><span class="pun">[</span><span class="pln">messagecount </span><span class="pun">-</span> <span class="lit">1</span><span class="pun">].</span><span class="pln">getDate</span><span class="pun">().</span><span class="pln">getTime</span><span class="pun">()</span> <span class="pun">-</span><span class="pln"> messages</span><span class="pun">[</span><span class="pln">messagecount </span><span class="pun">-</span><span class="pln"> num</span><span class="pun">].</span><span class="pln">getDate</span><span class="pun">().</span><span class="pln">getTime</span><span class="pun">())</span> <span class="pun">></span><span class="pln"> hours </span><span class="pun">*</span> <span class="lit">60</span> <span class="pun">*</span> <span class="lit">60</span> <span class="pun">*</span> <span class="lit">1000</span> <span class="pun">){</span> <span class="typ">MailApp</span><span class="pun">.</span><span class="pln">sendEmail</span><span class="pun">(</span><span class="pln">sender</span><span class="pun">,</span> <span class="str">"Auto Reply"</span><span class="pun">,</span> <span class="str">"您好!已经发了好几条信息了,可以停下来休息休息一下了!本短信由 Google </span><a title="View all posts in Apps Script" href="https://www.dujin.org/tag/apps-script" target="_blank" rel="noopener"><span class="str">Apps Script</span></a><span class="str"> 自动发出。"</span><span class="pun">);</span> <span class="pun">}</span><span class="pln"> messages</span><span class="pun">[</span><span class="pln">ii</span><span class="pun">].</span><span class="pln">markRead</span><span class="pun">();</span><span class="pln"> messages</span><span class="pun">[</span><span class="pln">ii</span><span class="pun">].</span><span class="pln">moveToTrash</span><span class="pun">();</span> <span class="pun">}</span> <span class="pun">}</span> <span class="pun">}</span> <span class="pun">}</span> <span class="kwd">catch</span> <span class="pun">(</span><span class="pln">err</span><span class="pun">)</span> <span class="pun">{</span><span class="pln"> console</span><span class="pun">.</span><span class="pln">error</span><span class="pun">(</span><span class="str">'for loop error: '</span> <span class="pun">+</span><span class="pln"> e</span><span class="pun">);</span> <span class="pun">}</span> <span class="pun">}</span></code>
点击左上角对该项目进行命名,例如:autoReplier,然后点击那个软盘图标进行保存。再单击调试
会提示你授权,你按提示授权即可。授权完后会提示没有找到文件之类的,不用管。
再次点击调试
,查看执行日志,如果没有任何提示说明脚本没有错误就 OK 了。
回到 Google Apps Script 主页,点击查看我的项目
,指向刚刚创建的项目,点击其右侧的更多按钮(那个按钮就是几个点),点击触发器
,按下图设置好保存即可。
选择触发器时间类型这里设置为最小的时间单位——分钟,意思当别人给你发送信息的时候,能在1分钟内进行回复。右侧的操作失败通知设置可以根据自己的喜好来定,别忘了点保存。
然后就可以啦,让小伙伴们给你发个 Google Voice 短信试一下吧。