Git Product home page Git Product logo

infobip-api-go-sdk's Introduction

Infobip API Go SDK

Workflow GitHub go.mod Go version License Lines

Go client SDK for Infobip's API Channels


๐Ÿ“ก Supported Channels

More channels to be added in the near future.

๐Ÿ” Authentication

Currently, infobip-api-go-sdk only supports API Key authentication, and the key needs to be passed during client creation. This will most likely change with future versions, once more authentication methods are included. You can get your base URL and API key by logging into Portal. Follow the instructions here.

๐Ÿ“ฆ Installation

Currently, infobip-api-go-sdk requires Go version 1.13 or greater. We'll do our best not to break older versions of Go unless it's absolutely necessary, but due to tooling constraints, we don't always test older versions.

infobip-api-go-sdk is compatible with modern Go modules. With Go installed, running the following:

go get "github.com/infobip-community/infobip-api-go-sdk/v3"

will add the client to the current module, along with all of its dependencies.

๐Ÿš€ Usage

import (
	"github.com/infobip-community/infobip-api-go-sdk/v3/pkg/infobip"
	"github.com/infobip-community/infobip-api-go-sdk/v3/pkg/infobip/models"
)

Construct a new Infobip client:

client, err := infobip.NewClient("https://myinfobipurl.com", "secret")

Or, passing your own HTTP client:

client, err := NewClient(baseURL, apiKey, WithHTTPClient(http.Client{Timeout: 3 * time.Second}))

Afterwards, use the various services on the client to access different channels of the Infobip API. For example:

client, err := infobip.NewClient(baseURL, apiKey)

// Send a WhatsApp text message
message := models.TextMsg{
    MsgCommon: models.MsgCommon{
        From: "111111111111",
        To:   "222222222222",
    },
    Content: models.TextContent{
		Text: "This message was sent from the Infobip API using the Go API client."
	},
}
msgResp, respDetails, err := client.WhatsApp.SendTextMsg(context.Background(), message)

Requests return the resource returned by the server (if applicable), response details and an error. Response details contain the raw http.Response object along with ErrorDetails which will be populated for cases where the server does not return a successful HTTP response code.

An error will only be returned if the underlying HTTP request failed (a network issue, failure reading the body, etc.). In other words, 4xx/5xx responses do not return an error, and the user should instead check for them by inspecting the ResponseDetails.HTTPResponse.StatusCode value. Note that for requests which require a payload (e.g. POST, PATCH), the object representing the payload will be validated before it is sent.

The channels of the client divide the API into multiple parts, corresponding to the Infobip Channels documented at https://www.infobip.com/docs/api#channels.

NOTE: Using the context package, the user can pass cancellation signals and deadlines to the underlying requests that the client makes. If you don't want to use this feature, then using context.Background() should be sufficient.

๐Ÿ‘€ Examples

The best way to learn how to use the library is to check the examples. The examples directory contains tests intended to be used for live testing all endpoints of available channels. The prerequisite for running an individual test is changing the apiKey and baseURL variables, along with certain message fields, depending on the endpoint (e.g. From/To for WhatsApp).

โš–๏ธ License

This library is distributed under the MIT license found in the LICENSE file.

infobip-api-go-sdk's People

Contributors

ecorona-ib avatar infobipdev avatar lvukadinovic-ib avatar pgrubacc avatar snyk-bot avatar strosek avatar ukmadlz avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

infobip-api-go-sdk's Issues

[BUG] WhatsApp send Template function validation restrict numbers on the template name

Describe the bug
In our company we create some WhatsApp templates with the following structure: template_event_name_version where version is a number. It works to create the template on Infobip and works to send messages using the API but when we try to send the same message with the SendTemplate function we get this error: Field validation for 'templateName' failed on the 'templatenamenotsnakecase' tag

To Reproduce
Steps to reproduce the behavior:

  1. Create the request with models.WATemplateMsgs.
  2. Set the templateName as lider_whatsapp_test_infobip_10.
  3. Use client.WhatsApp.SendTemplate function to send the message.
  4. See error: Field validation for 'templateName' failed on the 'templatenamenotsnakecase' tag

Expected behavior
The SDK should send the message with that template name, because the API send the same message.

Desktop (please complete the following information):

  • Version v3.3.1 I belive on GitHub says 3.1.1

Additional context
We need to have the version number on the name of the templates because they are always changing.

[BUG] WhatsApp send Template function validation restrict numbers of buttons to 3

Describe the bug
In out company, we created some WhatsApp templates with up to 10 buttons (since the platform allows it), but when testing the templates with more than 3 buttons, an error occurs during validation.

To Reproduce
Steps to reproduce the behavior:

  1. Create the request with models.WATemplateMsgs.
  2. Set the template with a list of buttons containing 4 or more elements.
  3. Use client.WhatsApp.SendTemplate function to send the message.
  4. See error: Field validation for 'Buttons' failed on the 'max' tag.

Expected behavior
The expected behavior would be that the WhatsApp message is sent with the 4 or more buttons.

Desktop (please complete the following information):

  • OS: MAC
  • Browser: Chrome
  • Infobip Version v3.4.1

[BUG] Your website can't register

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

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.