1
0
mirror of https://github.com/nikoksr/notify.git synced 2024-11-28 08:39:13 +02:00
notify/service/twilio
2022-09-12 16:54:09 +02:00
..
doc.go style(fmt): make fmt 2022-08-04 16:43:37 +02:00
mock_twilio_client.go style(fmt): make fmt 2022-09-12 16:54:09 +02:00
README.md feat(service): add twilio 2022-06-06 10:40:23 +03:00
twilio_test.go chore: gofumpt changes 2022-09-12 15:16:10 +03:00
twilio.go test: apply test conventions for twilio service 2022-09-12 14:57:33 +03:00

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")
}