Git Product home page Git Product logo

clickatell-go's Introduction

Clickatell GO Library

This package provides integration with the Clickatell SMS gateway.

Installation

To acquire the library in your project, simply run:

    go get github.com/arcturial/clickatell-go

Basic Usage

Sending messages relies on the Message object discussed further down. You can integrate either with the HTTP or REST API Clickatell provides. The API objects both provide the same methods and can be used interchangeably.

package main

import (
    "log"
    "github.com/arcturial/clickatell-go"
)

func main() {

    http := clickatell.Http(apiId, "user", "password", nil)

    m := clickatell.Message{
        Destination:    []string{"2"},
        Body:           "Testing",
    }

    httpResp, err := http.Send(m)

    log.Println(err)
    log.Println(httpResp)

    rest := clickatell.Rest("apiToken", nil)

    restResp, err := rest.Send(m)

    log.Println(err)
    log.Println(restResp)
}

Send Response

The Send() function will return a SendResponse object. The response objects are defined as response_[method].go files.

type SendResponse struct {
    Error ErrorResponse `json:"error"`

    Data struct {
        Message []SendResponseMessage `json:"message"`
    } `json:"data"`
}

type SendResponseMessage struct {
    To          string          `json:"to"`
    MessageId   string          `json:"apiMessageId"`
    Error       ErrorResponse   `json:"error"`
}

Interfacing with these response objects can be done as follows:

func main() {

    http := clickatell.Http(apiId, "user", "password", nil)

    m := clickatell.Message{
        Destination:    []string{"2"},
        Body:           "Testing",
    }

    httpResp, err := http.Send(m)

    for _, entry := range httpResp.Data.Message {
        log.Println(entry.Error)
        log.Println(entry.To)
        log.Println(entry.MessageId)
    }
}

Message Object

The message struct represents a Clickatell message and maps to the appropriate API parameters.

type Message struct {
    Binary          bool        // Send the message as binary (optional)
    ClientMsgId     string      // Specify the clientMessageId (optional)
    Concat          int         // Max concatenation value (optional)
    DeliveryQueue   int         // The user queue priority. (optional)
    Destination     []string    // The destination value. (required)
    Callback        int         // The callback type. (optional)
    Escalate        bool        // Specify the escalate value. (optional)
    MaxCredits      int         // The maximum amount of credits to use. (optional)
    Body            string      // The message body (required)
    Mo              bool        // Wether to use MO or not. (optional)
    ScheduledTime   int         // Scheduled delivery time. (optional)
    From            string      // The sender ID or "from" address. (optional)
    Unicode         bool        // Should the message be sent with unicode. (optional)
    ValidityPeriod  int         // How long the message is valid if queued. (optional)
}

Available Methods

Current available methods are:

Send(m Message)

GetBalance()

Note: These will be extended with future versions

Contributing

The library is still in it's initial release and is missing some methods/parameters. Contributions to the available methods or the way the source code is structured or optimized are welcome.

clickatell-go's People

Contributors

arcturial avatar

Watchers

Publifye AS avatar

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.