1
0
mirror of https://github.com/nikoksr/notify.git synced 2024-12-10 10:10:24 +02:00
notify/service/plivo
2021-02-23 01:23:31 +01:00
..
doc.go refactor(send): Add context.Context to parameter list of Send method 2021-02-18 03:33:30 +01:00
mock_plivoMsgClient.go refactor(send): Add context.Context to parameter list of Send method 2021-02-18 03:33:30 +01:00
plivo_test.go refactor(send): Add context.Context to parameter list of Send method 2021-02-18 03:33:30 +01:00
plivo.go docs(comment): fix wrong type name in comment 2021-02-23 01:23:31 +01:00
README.md refactor(send): Add context.Context to parameter list of Send method 2021-02-18 03:33:30 +01:00

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/nikoksr/notify"
  "github.com/nikoksr/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")
}