Send an outbound MMS using Go

    Overview

    While sending SMS is all too prevalent for consumers, one can make the SMS look more meaningful by including photos and gifs to provide more context about your message and deliver meaningful messages. To accomplish this, Plivo introduces you to the MMS feature. In this guide, we will show you how to make an MMS to any phone number.

    Start your implementation with Plivo to send outbound MMS using PHLO or the traditional API way. PHLO allows you to create and deploy your flows using its intuitive canvas in few clicks. Refer to the instructions from the respective tabs below to start your integration with PHLO or API as you wish.

    To send your first Outbound MMS, you can create and deploy a PHLO with a few clicks on the PHLO canvas. PHLO also lets you visually construct your entire use-case. With PHLO, you only pay for MMS you send/receive, and building with PHLO is free. You can refer to the below instructions in the Using PHLO tab to begin your implementation.

    Outline

    Send MMS

    Implementation

    In this section, we will guide you to create a PHLO to send an MMS.

    Prerequisites

    1. Create a Plivo Account(if you don’t have one already): You can sign up with your work email address and complete the phone verification step using your mobile number.
    2. Plivo Phone Number(Optional): To send messages to the United States and Canada, you must have a Plivo phone number that supports MMS. Numbers can be purchased from the Numbers section of your Plivo Console and use the same as the source number/from number for the outbound MMS. This number will also help you receive incoming MMS as you must have a MMS-enabled Plivo phone number to do the same. Please note that you can also purchase numbers using the Numbers API.

    Create the PHLO

    You can create a PHLO by referring to the below instructions to send an outbound MMS:

    Create a PHLO to send MMS

    • On the side navigation bar, click PHLO. The PHLO page will appear and display your existing PHLOs, if any. If this is your first PHLO, then the PHLO page will be empty.
    • Click Create New PHLO to build a new PHLO.
    • On the Choose your use-case window, click Build my own. The PHLO canvas will appear with the Start node.
      Note: The Start node is the starting point of any PHLO. You can choose between the four available trigger states of the Start node; Incoming MMS, Incoming Call, and API Request. For this PHLO, we will use the API Request trigger state.
    • From the list of components, on the left hand side, drag and drop the Send Message component onto the canvas. This will add a Send Message node onto the canvas.
    • Connect the Start node with the Send Message node, using the API Request trigger state.
    • Configure the Send Message node with the from_number using the From field. Enter the destination number you wish to send MMS in the To field. Update the Text field with your desired message & Media URL that has to be sent.
      Note: MMS is currently supported in US & CA only.
    • Once you have configured a node, click Validate to save the configurations.
    • After you complete the configurations, provide a friendly name for your PHLO and click Save. Your PHLO is now ready. You can trigger the PHLO and test it out. For more information, refer to the below section.

    Set up Your Go Dev Environment

    You must set up and install Go and Plivo’s Go SDK to send MMS. Here’s how.

    Install Go

    You can install Go from the Official Installer.

    Install Plivo Go Package

    • Create a project directory, run the following command:

      $ mkdir mygoapp
      
    • Change the directory to our project directory in the command line:

      $ cd mygoapp
      
    • You can install the Plivo Go package using the go command.

      $ go get github.com/plivo/plivo-go
      
    • You can also install by cloning this repository into your GOPATH.

    Trigger the PHLO

    Once you have created and setup your Node.js dev envrironment, you can go to your Plivo Consolse and copy the PHLO_ID. You can integrate a PHLO into your application workflow by making an API request to trigger the PHLO with the required payload.

    With Static Payload

    You can choose to either configure the mandatory params required for a PHLO while creating the PHLO itself or, you can pass the params as payload while triggering the PHLO from your app.

    Note: When you configure the params while creating the PHLO, the values(From & To) are hardcoded, and they act as static payload.

    With Static Payload

    Code

    Now, create a file called TriggerPhlo.go and paste the following code:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    
    package main
    
    import (
    	"fmt"
    	"plivo-go"
    )
    // Initialize the following params with corresponding values to trigger resources
    const authId = "auth_id"
    const authToken = "auth_token"
    const phloId = "phlo_id"
    
    func main() {
    	testPhloRunWithoutParams()
    }
    
    func testPhloRunWithoutParams() {
    	phloClient, err := plivo.NewPhloClient(authId, authToken, &plivo.ClientOptions{})
    	if err != nil {
    		panic(err)
    	}
    	phloGet, err := phloClient.Phlos.Get(phloId)
    	if err != nil {
    		panic(err)
    	}
    	response, err := phloGet.Run(nil)
    	if err != nil {
    		panic(err)
    	}
    	fmt.Printf("Response: %#v\n", response)
    }
    

    With Dynamic Payload

    To use dynamic values for the parameters, follow the below steps.

    • Select the Start node - under API request, fill the Payload key as From & To and keep the values empty, then click validate & save.

    With Dynamic Payload

    • Use the liquid templating params while creating the PHLO and pass the values while triggering the PHLO.

    With Dynamic Payload

    Code

    Now, create a file called TriggerPhlo.go and paste the following code:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    
    package main
    
    import (
    	"fmt"
    	"plivo-go"
    )
    // Initialize the following params with corresponding values to trigger resources
    const authId = "auth_id"
    const authToken = "auth_token"
    const phloId = "phlo_id"
    
    func main() {
    	testPhloRunWithParams()
    }
    
    func testPhloRunWithParams() {
    	phloClient, err := plivo.NewPhloClient(authId, authToken, &plivo.ClientOptions{})
    	if err != nil {
    		panic(err)
    	}
    	phloGet, err := phloClient.Phlos.Get(phloId)
    	if err != nil {
    		panic(err)
    	}
    	//pass corresponding from and to values
    	type params map[string]interface{}
    	response, err := phloGet.Run(params{
    		"From": "+14157778888",
    		"To":   "+14157778889",
    	})
    
    	if err != nil {
    		println(err)
    	}
    	fmt.Printf("Response: %#v\n", response)
    }
    

    You can get your Auth_ID and Auth_token from your dashboard AUTHID

    You can find the PHLO_ID on the PHLO Listing page. PHLO Listing

    Test and Validate

    You can save the file and use the below command to run it.

    go run TriggerPhlo.go
    
    Note: If you are using a Plivo Trial account for this example, you can only send MMS to phone numbers that have been verified with Plivo. Phone numbers can be verified at the Sandbox Numbers page.

    To implement send outbound MMS use-case in the traditional API way, you can refer to the instructions in the below section to begin your implementation.

    Outline

    Send MMS

    Implementation

    In this section, we will guide you in setting up an app using Plivo’s API to implement send outbound MMS use-case. First, let’s make sure you meet these prerequisites before we dive into the code.

    Prerequisites

    • Plivo Auth Id and Auth Token: You will find your Plivo Auth Id and Auth Token on the home screen of your Plivo Console. Click here to sign-up for a Plivo account if you haven’t already!

      Find Your Auth Credentials on Plivo Console

    • Plivo Phone Number(Optional): To send messages to the United States and Canada, you must have a Plivo phone number that supports MMS. Numbers can be purchased from the Numbers section of your Plivo Console and use the same as the source number/from number for the outbound MMS. This number will also help you receive incoming MMS as you must have a MMS-enabled Plivo phone number to do the same. Please note that you can also purchase numbers using the Numbers API.

      Buy a New Plivo Number

    Set up Your Go Dev Environment

    Once you have the above prerequisites set, You can follow the below instructions to create an app to send an outbound MMS to deliver your message.

    Install Go

    You can install Go from the Official Installer.

    Install Plivo Go Package

    • Create a project directory, run the following command:

      $ mkdir mygoapp
      
    • Change the directory to our project directory in the command line:

      $ cd mygoapp
      
    • You can install the Plivo Go package using the go command.

      $ go get github.com/plivo/plivo-go
      
    • You can also install by cloning this repository into your GOPATH.

    Create the Send MMS App

    Once you have the above prerequisites set, You can follow the below instructions to create an app to send an outbound MMS to deliver your message.

    Now, create a file called SendSMS.go and paste the following code:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    
    package main
    
    import (
            "fmt"
            plivo "github.com/plivo/plivo-go"
    )
    
    func main() {
    
            client, err := plivo.NewClient("AUTH_ID","AUTH_TOKEN",
                    &plivo.ClientOptions{})
            if err != nil {
                    panic(err)
            }
            createResp, err := client.Messages.Create(plivo.MessageCreateParams{
    				        Src: "+14151234567",
                    Dst:  "+14157654321",
                    Text: "Hello, from Go!",
                    Type: "mms",
                    MediaUrls: []string{"https://media.giphy.com/media/26gscSULUcfKU7dHq/source.gif"},
                    MediaIds: []string{"801c2056-33ab-499c-80ef-58b574a462a2"},
            })
            if err != nil {
                    panic(err)
            }
    
    Note:
    • Replace the placeholders auth_id & auth_token with your credentials from Plivo Console
    • We recommend that you store your credentials in the auth_id & auth_token environment variables, so as to avoid the possibility of accidentally committing them to source control. If you do this, you can initialize the client with no arguments and it will automatically fetch them from the environment variables
    • You can use os.Setenv & os.Getenv function to store environment variables and fetch them while initializing the client.
    • Replace the placeholder +14151234567 with the Phone number which you have purchased and +14157654321 with the phone number you will be sending MMS to.
    • Both plivo_source_number and +14157654321 should be in E.164 format
    • For other countries, this can be either a Alpha Sender ID or Numeric Sender ID based on the Sender ID support for the respective countries, to know more you can refer to the Sender ID Usage guide

    Test and Validate

    Once you have created the Send MMS App, save the file and use the below command to run it.

    go run SendSMS.go
    
    Note: If you are using a Plivo Trial account for this example, you can only send MMS to phone numbers that have been verified with Plivo. Phone numbers can be verified at the Sandbox Numbers page.

    Common Use Cases for Outbound MMS

    The majority of the use cases include an outbound MMS. For example, MMS Marketing, MMS Notifications, MMS Surveys, and so on.