twilio

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2024 License: MIT Imports: 5 Imported by: 0

README

Twilio (Message Service)

go.dev reference

Prerequisites

Navigate to Twilio console, create a new account or login with an existing one. You will find the Account SID and the Auth Token under the Account Info tab. You may also request a Twilio phone number, if required.

To test the integration with a phone number you can just use the sample code below.

Usage

package main

import (
	"context"
	"log"

	"github.com/nikoksr/notify"
	"github.com/nikoksr/notify/service/twilio"
)

func main() {
	twilioSvc, err := twilio.New("account_sid", "auth_token", "your_phone_number")
	if err != nil {
		log.Fatalf("twilio.New() failed: %s", err.Error())
	}

	twilioSvc.AddReceivers("recipient_phone_number")

	notifier := notify.New()
	notifier.UseServices(twilioSvc)

	err = notifier.Send(context.Background(), "subject", "message")
	if err != nil {
		log.Fatalf("notifier.Send() failed: %s", err.Error())
	}

	log.Println("notification sent")
}

Documentation

Overview

Package twilio provides message notification integration for Twilio (Message Service).

Usage:

package main

import (
	"context"
	"log"

	"github.com/nikoksr/notify"
	"github.com/nikoksr/notify/service/twilio"
)

func main() {
	twilioSvc, err := twilio.New("account_sid", "auth_token", "your_phone_number")
	if err != nil {
		log.Fatalf("twilio.New() failed: %s", err.Error())
	}

	twilioSvc.AddReceivers("recipient_phone_number")

	notifier := notify.New()
	notifier.UseServices(twilioSvc)

	err = notifier.Send(context.Background(), "subject", "message")
	if err != nil {
		log.Fatalf("notifier.Send() failed: %s", err.Error())
	}

	log.Println("notification sent")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service encapsulates the Twilio Message Service client along with internal state for storing recipient phone numbers.

func New

func New(accountSID, authToken, fromPhoneNumber string) (*Service, error)

New returns a new instance of Twilio notification service.

func (*Service) AddReceivers

func (s *Service) AddReceivers(phoneNumbers ...string)

AddReceivers takes strings of recipient phone numbers and appends them to the internal phone numbers slice. The Send method will send a given message to all those phone numbers.

func (*Service) Send

func (s *Service) Send(ctx context.Context, subject, message string) error

Send takes a message subject and a message body and sends them to all previously set phone numbers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL