TwilioMatthew SetterTutorial
How to Create and Send vCards with Go
Summary
Sharing contact details by copying text between apps is ineffective compared to sending a vCard, a structured data format supported by major operating systems and email clients. This tutorial demonstrates creating vCards in Go using the go-vcard package, which handles fields such as formatted name, structured name, street address, telephone number, email address, and URL. The code writes the vCard to a .vcf file with version 4.0 using the go-vcard encoder and constants from the package, exiting on failure. The vCard file is uploaded to Twilio Assets, a static file hosting service bundled with every Twilio account, to make it publicly accessible for the SMS. The Twilio Go SDK sends an SMS with a message body and the vCard URL as a media attachment via the Programmable Messaging API, allowing recipients to open it in their contacts app.
Approach / What changed
Create a vCard using the go-vcard package, write it to a .vcf file, upload the file to Twilio Assets for public hosting, then send an SMS with the vCard URL as a media attachment using the Twilio Go SDK.
Takeaways
vCard is a structured data format for contact information supported by major operating systems and email clients, enabling organized sharing of details like name, phone, and address.
The go-vcard package in Go can encode vCard files with fields such as formatted name, structured name, street address, telephone number, email address, and URL.
Twilio Assets provides static file hosting to make vCard files publicly accessible for inclusion as media attachments in SMS messages sent via the Twilio Programmable Messaging API.
FAQ
How do you create a vCard file in Go?
Use the go-vcard package to create a vcard.Card object, add fields such as formatted name, address, telephone, email, and URL, then encode it to a .vcf file using vcard.NewEncoder.
How do you make a vCard file accessible for SMS?
Upload the .vcf file to Twilio Assets in the Twilio Console, set its visibility to Public, and copy the provided URL to use as the media attachment in the SMS.
How do you send a vCard via SMS using Twilio?
Use the Twilio Go SDK to create a message with the vCard URL as a media attachment via the Programmable Messaging API, setting the sender, recipient, and message body.
Source and freshness
- Source
- twilio.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.