plivo

package
v0.42.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: MIT Imports: 6 Imported by: 0

README

Plivo

go.dev reference

Prerequisites

You will need to have a Plivo account and the following things:

  1. Auth ID and Auth Token from Plivo console.
  2. An active rented Plivo phone number.

Usage

package main

import (
  "context"
  "log"

  "github.com/casdoor/notify"
  "github.com/casdoor/notify/service/plivo"
)

func main() {
  plivoSvc, err := plivo.New(
    &plivo.ClientOptions{
      AuthID:    "<Your-Plivo-Auth-Id>",
      AuthToken: "<Your-Plivo-Auth-Token>",
    }, &plivo.MessageOptions{
      Source: "<Your-Plivo-Source-Number>",
    })
  if err != nil {
    log.Fatalf("plivo.New() failed: %s", err.Error())
  }

  plivoSvc.AddReceivers("Destination1")

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

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

  log.Printf("notification sent")
}

Documentation

Overview

Package plivo provides message notification integration for Plivo.

Usage:

package main

import (
	"log"

	"github.com/casdoor/notify"
	"github.com/casdoor/notify/service/plivo"
)

func main() {
	plivoSvc, err := plivo.New(
		&plivo.ClientOptions{
			AuthID:    "<Your-Plivo-Auth-Id>",
			AuthToken: "<Your-Plivo-Auth-Token>",
		}, &plivo.MessageOptions{
			Source: "<Your-Plivo-Source-Number>",
		})
	if err != nil {
		log.Fatalf("plivo.New() failed: %s", err.Error())
	}

	plivoSvc.AddReceivers("Destination1")

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

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

	log.Printf("notification sent")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientOptions

type ClientOptions struct {
	AuthID    string // If empty, env variable PLIVO_AUTH_ID will be used
	AuthToken string // If empty, env variable PLIVO_AUTH_TOKEN will be used

	// Optional
	HTTPClient *http.Client // Bring Your Own Client
}

ClientOptions allow you to configure a Plivo SDK client.

type MessageOptions

type MessageOptions struct {
	Source string // a Plivo source phone number or a Plivo Powerpack UUID

	// Optional
	CallbackURL    string // URL to which status update callbacks for the message should be sent
	CallbackMethod string // The HTTP method to be used when calling CallbackURL - GET or POST(default)
}

MessageOptions allow you to configure options for sending a message.

type Service

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

Service is a Plivo client

func New

func New(cOpts *ClientOptions, mOpts *MessageOptions) (*Service, error)

New creates a new instance of plivo service.

func (*Service) AddReceivers

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

AddReceivers adds the given destination phone numbers to the notifier.

func (*Service) Send

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

Send sends a SMS via Plivo to all previously added receivers.

Jump to

Keyboard shortcuts

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