gocm

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: MIT Imports: 3 Imported by: 0

README

gocm

GitHub go.mod Go version of a Go module Go Go Report Card Go Doc

With this small library it should be possible to send SMS, WhatsApp & Co messages via cm.com. And, of course, to make other functions of the API usable.

Install

go get github.com/jjideenschmiede/gocm

How to use?

Business Messaging

In order to send one, or more messages via the Business Messages API, you can use the following function. Here you can find an additional description from the manufacturer.

Currently the following channels can be used: WhatsApp, Push, RCS, Viber, SMS

// Define body
body := gocm.MessageBody{
    Messages: gocm.MessageBodyMessages{
        Authentication: gocm.MessageBodyAuthentication{
            Producttoken: "",
        },
        Msg: []gocm.MessageBodyMsg{},
    },
}

// Create a message
body.Messages.Msg = append(body.Messages.Msg, gocm.MessageBodyMsg{
    AllowedChannels: []string{"SMS"},
    From:            "Test",
    To:              []gocm.MessageBodyTo{},
    Body: gocm.MessageBodyBody{
        Type:    "auto",
        Content: "Test message",
    },
})

// Add receiver
body.Messages.Msg[0].To = append(body.Messages.Msg[0].To, gocm.MessageBodyTo{
    Number: "004941521234567",
})

// Send message
message, err := gocm.Message(body)
if err != nil {
    fmt.Println(err)
} else {
    fmt.Println(message)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Path, Method string
	Body         []byte
}

Config is to define config data

func (Config) Send

func (c Config) Send() (*http.Response, error)

Send is to send a new request

type MessageBody

type MessageBody struct {
	Messages MessageBodyMessages `json:"messages"`
}

MessageBody is to structure the body data

type MessageBodyAuthentication

type MessageBodyAuthentication struct {
	Producttoken string `json:"producttoken"`
}

type MessageBodyBody

type MessageBodyBody struct {
	Type    string `json:"type"`
	Content string `json:"content"`
}

type MessageBodyMessages

type MessageBodyMessages struct {
	Authentication MessageBodyAuthentication `json:"authentication"`
	Msg            []MessageBodyMsg          `json:"msg"`
}

type MessageBodyMsg

type MessageBodyMsg struct {
	AllowedChannels []string        `json:"allowedChannels"`
	From            string          `json:"from"`
	To              []MessageBodyTo `json:"to"`
	Body            MessageBodyBody `json:"body"`
}

type MessageBodyTo

type MessageBodyTo struct {
	Number string `json:"number"`
}

type MessageReturn

type MessageReturn struct {
	Details   string `json:"details"`
	ErrorCode int    `json:"errorCode"`
	Messages  []struct {
		To               string      `json:"to"`
		Status           string      `json:"status"`
		Reference        interface{} `json:"reference"`
		Parts            int         `json:"parts"`
		MessageDetails   interface{} `json:"messageDetails"`
		MessageErrorCode int         `json:"messageErrorCode"`
	} `json:"messages"`
}

MessageReturn is to decode the json data

func Message

func Message(body MessageBody) (MessageReturn, error)

Message is to send a new message via the business messaging api

Jump to

Keyboard shortcuts

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