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.
The DLLs included in the package may not be the latest version. We recommend using NuGet to obtain the latest version of the packages:
Install-Package RestSharp
Install-Package Newtonsoft.Json
Install-Package JsonSubTypes
NOTE: RestSharp versions greater than 105.1.0 have a bug which causes file uploads to fail. See RestSharp#742
Run the following command to generate the DLL
/bin/sh build.sh
build.bat
Then include the DLL (under the bin
folder) in the C# project, and use the namespaces:
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Model;
A .nuspec
is included with the project. You can follow the Nuget quickstart to create and publish packages.
This .nuspec
uses placeholders from the .csproj
, so build the .csproj
directly:
nuget pack -Build -OutputDirectory out Org.OpenAPITools.csproj
Then, publish to a local feed or other host and consume the new package via Nuget as usual.
using System.Collections.Generic;
using System.Diagnostics;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Model;
namespace Example
{
public class Example
{
public static void Main()
{
Configuration.Default.BasePath = "https://api.chat-api.com";
// Configure API key authorization: instanceId
Configuration.Default.ApiKey.Add("instanceId", "YOUR_API_KEY");
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// Configuration.Default.ApiKeyPrefix.Add("instanceId", "Bearer");
// Configure API key authorization: token
Configuration.Default.ApiKey.Add("token", "YOUR_API_KEY");
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// Configuration.Default.ApiKeyPrefix.Add("token", "Bearer");
var apiInstance = new Class1InstanceApi(Configuration.Default);
try
{
// Updates the QR code after its expired
InlineResponse2002 result = apiInstance.Expiry();
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling Class1InstanceApi.Expiry: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
}
All URIs are relative to https://api.chat-api.com
Type: API key
API key parameter name: instanceId
Location: URL query string
Type: API key
API key parameter name: token
Location: URL query string
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 the Newtonsoft Json.NET NuGet Package. If the automatic NuGet package restore is enabled, these dependencies will be installed automatically. Therefore, you will need internet access for build.
"This library requires Visual Studio 2017 for compilation."
Ctrl+Shift+B
shortcut key or using the Build
menu as shown below.The build process generates a portable class library, which can be used like a normal class library. The generated library is compatible with Windows Forms, Windows RT, Windows Phone 8, Silverlight 5, Xamarin iOS, Xamarin Android and Mono. More information on how to use can be found at the MSDN Portable Class Libraries documentation.
The following section explains how to use the messengersAPI library in a new console project.
For starting a new project, right click on the current solution from the solution explorer and choose Add -> New Project
.
Next, choose "Console Application", provide a TestConsoleProject
as the project name and click OK
.
The new console project is the entry point for the eventual execution. This requires us to set the TestConsoleProject
as the start-up project. To do this, right-click on the TestConsoleProject
and choose Set as StartUp Project
form the context menu.
In order to use the messengersAPI library in the new project, first we must add a projet reference to the TestConsoleProject
. First, right click on the References
node in the solution explorer and click Add Reference...
.
Next, a window will be displayed where we must set the checkbox
on messengersAPI.Tests
and click OK
. By doing this, we have added a reference of the messengersAPI.Tests
project into the new TestConsoleProject
.
Once the TestConsoleProject
is created, a file named Program.cs
will be visible in the solution explorer with an empty Main
method. This is the entry point for the execution of the entire solution.
Here, you can add code to initialize the client library and acquire the instance of a Controller class. Sample code to initialize the client library and using controller methods is given in the subsequent sections.
The generated SDK also contain one or more Tests, which are contained in the Tests project. In order to invoke these test cases, you will need NUnit 3.0 Test Adapter Extension for Visual Studio. Once the SDK is complied, the test cases should appear in the Test Explorer window. Here, you can click Run All to execute these test cases.