Rich Communication Services (RCS) is the next evolution of SMS messaging, offering enhanced features like rich media, interactive buttons, and quick replies. In this tutorial, we'll build a Go application that implements RCS messaging using the Pinnacle API, complete with media cards, quick replies, and webhook handling for interactive responses.

Pre-reqs

  • Go installed on your system
  • Basic understanding of Go programming
  • (Optional, but recommended) Your own registered agent (Register here)
  • A Pinnacle API key (Get yours here)
  • (optional) ngrok or similar tool for webhook testing

Project Setup

First, let's set up our project structure and dependencies. We'll need to install the godotenv package for environment variable management:

bash
go mod init rcs-demo go get github.com/joho/godotenv # Used to load our .env

Create a .env file in your project root:

PINNACLE_API_KEY=your_api_key_here

Creating the Pinnacle Client

We'll start by creating a client struct to handle our API interactions:

go
type PinnacleClient struct { apiKey string baseURL string client *http.Client }

I'd recommend loading your api key from the .env file using the package godotenv.

Implementing RCS Message Types

Now that we a connection to our client, we can start sending messages.

Sending a Basic Text Message

Let's start with a simple text message:

go
func send_basic_rcs() { url := client.baseURL + "/send/rcs" payloadData := map[string]interface{}{ "from": "test", "to": "your_number",

Once we send this, we should see a text from our agent that says "Hello, World!"

2. Quick Reply Buttons

Next, we'll add quick reply buttons that users can tap:

go
func send_rcs_with_quick_replies() { payloadData := map[string]interface{}{ "from": "test", "to": "+16287261512", "text": "Hello, World!",

3. Media Cards

For rich media content, we can create cards with images or videos:

go
func send_rcs_media_card() { payloadData := map[string]interface{}{ "from": "test", "to": "+16287261512", "cards": []map[string]interface{}{

Handling Webhooks

To make our program interactive, we'll implement a webhook handler to process user responses:

go
func webhookHandler(w http.ResponseWriter, r *http.Request) { // Parse incoming webhook data var webhookData map[string]interface{} if err := json.Unmarshal(body, &webhookData)