Giter VIP home page Giter VIP logo

sms's Introduction

Golang SMS Gateway

This is a Go Package for SMS Gateway

List of supported gateways:

Install

go get https://github.com/mousav1/sms

Configure

Add the config file to the project

In the configuration file, you can choose the default driver and also set the settings of each driver.

{
    "default_driver": "Ghasedak",
    "drivers": {
      "Ghasedak": {
        "api_key": "api_key",
        "line_number": "line_number",
        "host": "api.ghasedak.me"
      }
    }
  }

Usage

In your code just use it like this.

	config, err := sms.LoadConfig("sms_config.json")
	if err != nil {
		fmt.Println("Failed to load SMS smsGateway configuration:", err)
		return
	}

	smsGateway, err := provider.NewSMSGateway(config)
	if err != nil {
		fmt.Println("Failed to create SMS smsGateway:", err)
		return
	}

	// Use the SMS smsGateway to send messages
	response, err := smsGateway.SendSMS("Number", "message")
	if err != nil {
		fmt.Println("Failed to send SMS:", err)
		return
	}

Add custom driver

1- Add custom driver to the driver directory

2- Create the code structure for the driver

3- Implement driver methods:

// CreateProvider creates an instance of the mydriver provider.
func (g *mydriver) CreateProvider(config config.DriverConfig) (sms.SMSProvider, error) {}

// SendSMS sends an SMS using mydriver.
func (g *mydriver) SendSMS(to, message string) (sms.Response, error) {}

4- Add the driver to the provider.go in package:

func GetProviderFactory(driverName string) (SMSProviderFactory, error) {
	switch driverName {
	case "Ghasedak":
		return &driver.Ghasedak{}, nil
	case "mydriver":
		return &driver.mydriver{}, nil
	default:
		return nil, fmt.Errorf("unsupported driver: %s", driverName)
	}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.