Download SDK and unpack the archive. Connect SDK to your project.
The REST API allows you to receive and send messages through your messengers account.
Parameters in GET queries pass query string. Parameters in POST requests — through the JSON-encoded request body. The authorization token is always passed to query string (?token=xxxxxx).
The messengers API is based on the messengers WEB protocol and excludes the ban both when using libraries from mgp25 and the like. Despite this, your account can be banned by anti-spam system messengers after several clicking the "block" button.
Get an API keyGOPATH
environment variable is set in the system variables. If not, set it to your workspace directory where you will be adding your Go projects.go get github.com/apimatic/unirest-go
This will install unirest-go in the GOPATH
you specified in the system variables.
Now follow the steps mentioned below to build your SDK:
Import
option in File
menu.General -> Existing Projects into Workspace
option from the tree list.Select root directory
, provide path to the unzipped archive for the generated code. Once the path is set and the Project becomes visible under Projects
click Finish
The following section explains how to use the messengersAPILib library in a new project.
Create a new project in Eclipse by File
-> New
-> Go Project
Name the Project as Test
and click Finish
Create a new directory in the src
directory of this project
Name it test.com
Now create a new file inside src/test.com
Name it testsdk.go
In this Go file, you can start adding code to initialize the client library. Sample code to initialize the client library and using its methods is given in the subsequent sections.
You need to import your generated library in this project in order to make use of its functions. In order to import the library, you can add its path in the GOPATH
for this project. Follow the below steps:
Right click on the project name and click on Properties
Choose Go Compiler
from the side menu. Check Use project specific settings
and uncheck Use same value as the GOPATH environment variable.
. By default, the GOPATH value from the environment variables will be visible in Eclipse GOPATH
. Do not remove this as this points to the unirest dependency.
Append the library path to this GOPATH
Once the path is appended, click on OK
Right click on the project name and click on Build Project
If the build is successful, right click on your Go file and click on Run As
-> Go Application
To initialize and authenticate the API client, the following parameters need to be passed.
Parameter | Type | Description |
---|---|---|
token | string | |
instanceId | string | Your instance number Default: '123' |
protocol | models_pkg.ProtocolEnum | Default: models_pkg.ProtocolEnumFromValue("https") |
server | string | Your server number Default: '2' |
The API client can be initialized as following.
client.Configuration().SetInstanceId("123")
client.Configuration().SetProtocol(models_pkg.Protocol_HTTPS)
client.Configuration().SetServer("2")
Token := "token"
client := messengersAPIClient.NewmessengersAPIClient(Token)
The SDK can be configured to use a different environment for making API calls. Available environments are:
Name | Value | Description |
---|---|---|
production | PRODUCTION | Default New common server url |
environment2 | ENVIRONMENT2 | Old style server url |
The environment should be set in the CONFIGURATION before the client is initialized.
configuration_pkg.Environment = configuration_pkg.PRODUCTION;
This API uses Custom Query Parameter
At the very beginning, we need to connect messengers with our script, so as we write the code, we check its operation. To do this, go to your personal account and get a QR code there. Next, open messengers on your smartphone, go to Settings -> messengers Web -> Scan a QR code.
Now we need to indicate a WebHook URL so the server can run the scrip when new messages arrive. Indicate a direct link to your script, e.g. https://domain.com/PHP/messengersbot.php. You can’t indicate server IP only, but you can indicate the port.
{*