The SDK allows you to receive and send messages through your messengers account. Sign up now
Download SDK and unpack the archive. Connect SDK to your project.
Building the API client library requires:
To install the API client library to your local Maven repository, simply execute:
mvn clean install
To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:
mvn clean deploy
Refer to the OSSRH Guide for more information.
Add this dependency to your project's POM:
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>openapi-java-client</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
Add this dependency to your project's build file:
compile "org.openapitools:openapi-java-client:1.0.0"
At first generate the JAR by executing:
mvn clean package
Then manually install the following JARs:
target/openapi-java-client-1.0.0.jar
target/lib/*.jar
Please follow the installation instruction and execute the following Java code:
// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.auth.*;
import org.openapitools.client.models.*;
import org.openapitools.client.api.Class1InstanceApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://api.chat-api.com");
// Configure API key authorization: instanceId
ApiKeyAuth instanceId = (ApiKeyAuth) defaultClient.getAuthentication("instanceId");
instanceId.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//instanceId.setApiKeyPrefix("Token");
// Configure API key authorization: token
ApiKeyAuth token = (ApiKeyAuth) defaultClient.getAuthentication("token");
token.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//token.setApiKeyPrefix("Token");
Class1InstanceApi apiInstance = new Class1InstanceApi(defaultClient);
try {
InlineResponse2002 result = apiInstance.expiry();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling Class1InstanceApi#expiry");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
All URIs are relative to https://api.chat-api.com
Authentication schemes defined for the API:
It's recommended to create an instance of ApiClient
per thread in a multithreaded environment to avoid any potential issues.
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. You can’t indicate server IP only, but you can indicate the port.
The generated code uses a few Maven dependencies e.g., Jackson, UniRest, and Apache HttpClient. The reference to these dependencies is already added in the pom.xml file will be installed automatically. Therefore, you will need internet access for a successful build.
File -> Import
.Existing Java Project
and click Next
.Finish
.The following section explains how to use the messengersAPI library in a new console project.
For starting a new project, click the menu command File > New > Project
.
Next, choose Maven > Maven Project
and click Next
.
Here, make sure to use the current workspace by choosing Use default Workspace location
, as shown in the picture below and click Next
.
Following this, select the quick start project type to create a simple project with an existing class and a main
method. To do this, choose maven-archetype-quickstart
item from the list and click Next
.
In the last step, provide a Group Id
and Artifact Id
as shown in the picture below and click Finish
.
The created Maven project manages its dependencies using its pom.xml
file. In order to add a dependency on the messengersAPILib client library, double click on the pom.xml
file in the Package Explorer
. Opening the pom.xml
file will render a graphical view on the cavas. Here, switch to the Dependencies
tab and click the Add
button as shown in the picture below.
Clicking the Add
button will open a dialog where you need to specify messengersAPI in Group Id
and messengersAPILib in the Artifact Id
fields. Once added click OK
. Save the pom.xml
file.
Once the SimpleConsoleApp
is created, a file named App.java
will be visible in the Package Explorer with a main
method. This is the entry point for the execution of the created project.
Here, you can add code to initialize the client library and instantiate a Controller class. Sample code to initialize the client library and using controller methods is given in the subsequent sections.
The generated code and the server can be tested using automatically generated test cases. JUnit is used as the testing framework and test runner.
In Eclipse, for running the tests do the following: