Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Add support for Twilio SMS outgoing media attachments (MMS) #951

Merged
merged 4 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions docs/readme-twiliosms.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ Then you need to write your bot. First, create a TwilioSMSBot instance and pass
* `twilio_number`: your app's phone number, found in your [Phone Numbers Dashboard](https://www.twilio.com/console/phone-numbers/dashboard) **The phone number format must be: `+15551235555`**

```js
const TwilioSMSBot = require('botkit-sms')
const controller = TwilioSMSBot({
const Botkit = require('botkit')
const controller = Botkit.twiliosmsbot({
account_sid: process.env.TWILIO_ACCOUNT_SID,
auth_token: process.env.TWILIO_AUTH_TOKEN,
twilio_number: process.env.TWILIO_NUMBER
Expand Down Expand Up @@ -103,6 +103,23 @@ controller.hears('.*', 'message_received', (bot, message) => {

See full example in the `examples` directory of this repo.

### Sending media attachments (MMS)

To send media attachments, pass a `mediaUrl` property to any of Botkit's outgoing messages functions (`reply`, `say`, `ask`, etc.) with an optional `text` property for text that goes along with your attachment.

```js
/*
Sending an attachment
*/
bot.reply(message, {
text: 'Optional text to go with attachment',
mediaUrl: 'https://i.imgur.com/9n3qoKx.png'
})
```

> Note: your Twilio number as well as the recipient's phone must support MMS for media attachments to work

For more details on outgoing media attachments and a full list of accepted MIME types, go to [Twilio's docs on media attachment](https://www.twilio.com/docs/api/rest/accepted-mime-types).

## Documentation

Expand Down
4 changes: 4 additions & 0 deletions lib/TwilioSMSBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ function TwilioSMS(configuration) {
to: message.channel
};

if (message.hasOwnProperty('medaUrl')) {
sms.mediaUrl = message.mediaUrl
}

client.messages.create(sms, function(err, message) {

if (err) {
Expand Down