生成 VCard 并通过 Twilio 发送 [英] Generate VCard and Send Via Twilio

查看:21
本文介绍了生成 VCard 并通过 Twilio 发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 Twilio + Parse 应用程序,它允许用户通过短信分享他们的联系信息.我有一个示例 Vcard 作为 javascript 中的字符串:

I am writing a Twilio + Parse app which lets users share their contact info via SMS. I have a sample Vcard as a string in javascript:

  message = '';
  message += 'BEGIN:VCARD';
  message += 'BDAY;VALUE=DATE:1963-09-21';
  message += 'VERSION:3.0';
  message += 'N:Stenerson;Derik';
  message += 'FN:Derik Stenerson';
  message += 'ORG:Microsoft Corporation';
  message += 'ADR;TYPE=WORK,POSTAL,PARCEL:;;One Microsoft Way;Redmond;WA;98052-6399;USA';
  message += 'TEL;TYPE=WORK,MSG:+1-425-936-5522';
  message += 'TEL;TYPE=WORK,FAX:+1-425-936-7329';
  message += 'EMAIL;TYPE=INTERNET:deriks@Microsoft.com';
  message += 'END:VCARD';
  message += 'BEGIN:VCARD';
  message += 'VERSION:3.0';
  message += 'N:Ganguly;Anik';
  message += 'FN:Anik Ganguly';
  message += 'ORG: Open Text Inc.';
  message += 'ADR;TYPE=WORK,POSTAL,PARCEL:;Suite 101;38777 West Six Mile Road;Livonia;MI;48152;USA';
  message += 'TEL;TYPE=WORK,MSG:+1-734-542-5955';
  message += 'EMAIL;TYPE=INTERNET:ganguly@acm.org';
  message += 'END:VCARD';
  message += 'BEGIN:VCARD';
  message += 'VERSION:3.0';
  message += 'N:Moskowitz;Robert';
  message += 'FN:Robert Moskowitz';
  message += 'EMAIL;TYPE=INTERNET:rgm-ietf@htt-consult.com';
  message += 'END:VCARD';

我想弄清楚如何将它作为 vcard 发送到电话号码,以便手机检测到它而不是文本.

And I am trying to figure out how to send this to a phone number as a vcard so the phone detects it instead of the text.

我有一个方法:

function respondWithMessage(message, response) {
  response.set('Content-Type', 'text/xml');
  var xmlVersion = '<?xml version="1.0" encoding="UTF-8"?>
';
  message = '<Message>
' + message + '
</Message>';
  message = '<Response>
' + message + '
</Response>';
  message = xmlVersion + message;
  response.send(message);
}

我可以用它发送短信.在他们的文档中,Twilio 声明这里支持 text/vcard 消息:https://www.twilio.com/docs/api/rest/accepted-mime-types但我一直无法让它工作.您能否举例说明如何使用 Twilio 通过短信发送此 VCard?谢谢!

With which I am able to send text messages. In their documentation, Twilio states that text/vcard messages are supported here: https://www.twilio.com/docs/api/rest/accepted-mime-types But I have been unable to get it to work. Could you provide an example of how to send this VCard via SMS with Twilio? Thanks!

推荐答案

Twilio 开发人员布道者在这里.如果您尝试开始一条新消息,那么您不需要使用 TwiML,而只需使用其余 API 从您的服务器发送信息即可.

Twilio developer evangelist here. If you're trying to start a new message, then you don't need to use TwiML, but can simply use the rest API to send the information from your server.

对于 Parse.com,它应该是这样的:

With Parse.com it should be something like the following:

// Require and initialize the Twilio module with your credentials
var client = require('twilio')('ACCOUNT_SID', 'AUTH_TOKEN');

// Send an SMS message
client.sendSms({
    to:'to', 
    from: 'from', 
    body: 'Hello world!',
    mediaUrl: your-vcard-url
  }, function(err, responseData) { 
    if (err) {
      console.log(err);
    } else { 
      console.log(responseData.from); 
      console.log(responseData.body);
    }
  }
);

所以你现在需要做的就是确保 your-vcard-url 可以被 Twilio 访问,并且它的 mime 类型设置为 text/vcard.

So all you need to do now, is make sure your-vcard-url is accessible by Twilio, and that its mime type is set to be text/vcard.

换句话说,您不能只通过短信发送 vcard 的内容,而是需要告诉 Twilio vcard 的实际位置,以便将其包含在消息中.

In other words, you can't just send the contents of the vcard via text message, but need to tell Twilio where the vcard actually is, so it includes it in the message.

vcard 的有效 URL 示例是 这个.希望对你有帮助

An example of a valid URL for a vcard would be this one. Hope this helps you

这篇关于生成 VCard 并通过 Twilio 发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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