Creating and sending vCard files via MMS

1k views Asked by At

I'm trying to send vCard files (which allow you to save contacts on mobile devices) using Twilio's API and vobject.

Here's my code:

import vobject
import requests
from twilio.rest import Client

account_sid = 'MY_SID_HIDDEN'
auth_token = 'AUTH_TOKEN_HIDDEN'

j = vobject.vCard()
j.add('n')
j.n.value = vobject.vcard.Name(family='Harris', given='Jeffrey')
j.add('fn')
j.fn.value = 'Jeffrey Harris'
j.add('email')
j.email.value = '[email protected]'
j.email.type_param = 'Internet'

client = Client(account_sid, auth_token)

client.api.account.messages.create(
    to="NUMBER_HIDDEN",
    from_="NUMBER_HIDDEN",
    body=j
)

When my device receives the message, it looks like this:

<VCARD| [<EMAIL{'TYPE': ['Internet']}[email protected]>, <FN{}Jeffrey Harris>, <N{} Jeffrey  Harris >]>

Why is this happening?

1

There are 1 answers

2
Who's there... Me On

I understand what you want to do, but there are a couple issues.

  1. Vcards are files; you have put marked up text in a text field (body).
  2. For attaching files using the API, you point it at a URL that the Twilio Server can access and make sure you properly declare your mime-type encoding in the API and on server where the card will be stored.

Note: I'm not sure if the mime-type is required anymore, as they don't use it on this example for a attaching picture (https://www.twilio.com/docs/api/messaging/send-messages#send-a-message-with-an-image-url ; change the language to python).

You would attach the file (vcard) using mediaUrl.
ex// mediaUrl=https://qrstuff.com/vcard.download/dec91a6d6/yo_yo_ma_vCard.vcf