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 SDK requires ARC (Automatic Reference Counting) to be enabled in the Xcode project.
Add the following to the Podfile:
pod 'OpenAPIClient', :git => 'https:////.git'
To specify a particular branch, append , :branch => 'branch-name-here'
To specify a particular commit, append , :commit => '11aa22'
Put the SDK under your project folder (e.g. /path/to/objc_project/Vendor/OpenAPIClient) and then add the following to the Podfile:
pod 'OpenAPIClient', :path => 'Vendor/OpenAPIClient'
Import the following:
#import <OpenAPIClient/OAIApiClient.h>
#import <OpenAPIClient/OAIDefaultConfiguration.h>
// load models
#import <OpenAPIClient/OAIAck.h>
#import <OpenAPIClient/OAIBanSettings.h>
#import <OpenAPIClient/OAIBanTestAction.h>
#import <OpenAPIClient/OAIBanTestStatus.h>
#import <OpenAPIClient/OAIChat.h>
#import <OpenAPIClient/OAIchatIdProp.h>
#import <OpenAPIClient/OAIChatUpdate.h>
#import <OpenAPIClient/OAIChats.h>
#import <OpenAPIClient/OAIClearActionsQueueStatus.h>
#import <OpenAPIClient/OAIClearMessagesQueueStatus.h>
#import <OpenAPIClient/OAICreateGroupAction.h>
#import <OpenAPIClient/OAICreateGroupStatus.h>
#import <OpenAPIClient/OAIForwardMessageRequest.h>
#import <OpenAPIClient/OAIGroupParticipantAction.h>
#import <OpenAPIClient/OAIGroupParticipantStatus.h>
#import <OpenAPIClient/OAIInlineResponse200.h>
#import <OpenAPIClient/OAIInlineResponse2001.h>
#import <OpenAPIClient/OAIInlineResponse2002.h>
#import <OpenAPIClient/OAIInlineResponse2003.h>
#import <OpenAPIClient/OAIInlineResponse2004.h>
#import <OpenAPIClient/OAIInlineResponse2005.h>
#import <OpenAPIClient/OAIInlineResponse2005Update.h>
#import <OpenAPIClient/OAIInlineResponse401.h>
#import <OpenAPIClient/OAIInstanceStatus.h>
#import <OpenAPIClient/OAIInstanceStatusAction.h>
#import <OpenAPIClient/OAIInstanceStatusLink.h>
#import <OpenAPIClient/OAIInstanceStatusStatusData.h>
#import <OpenAPIClient/OAIInstanceStatusStatusDataActions.h>
#import <OpenAPIClient/OAIMessage.h>
#import <OpenAPIClient/OAIMessages.h>
#import <OpenAPIClient/OAIOutboundAction.h>
#import <OpenAPIClient/OAIOutboundActions.h>
#import <OpenAPIClient/OAIOutboundMessage.h>
#import <OpenAPIClient/OAIOutboundMessages.h>
#import <OpenAPIClient/OAIPhoneProp.h>
#import <OpenAPIClient/OAIReadChatAction.h>
#import <OpenAPIClient/OAIReadChatStatus.h>
#import <OpenAPIClient/OAISendContactRequest.h>
#import <OpenAPIClient/OAISendFileRequest.h>
#import <OpenAPIClient/OAISendLinkRequest.h>
#import <OpenAPIClient/OAISendLocationRequest.h>
#import <OpenAPIClient/OAISendMessageRequest.h>
#import <OpenAPIClient/OAISendMessageStatus.h>
#import <OpenAPIClient/OAISendPTTRequest.h>
#import <OpenAPIClient/OAISendVCardRequest.h>
#import <OpenAPIClient/OAISetWebhookStatus.h>
#import <OpenAPIClient/OAISettings.h>
#import <OpenAPIClient/OAIStatus.h>
#import <OpenAPIClient/OAIStatuses.h>
#import <OpenAPIClient/OAIWebhookStatus.h>
#import <OpenAPIClient/OAIWebhookUrl.h>
// load API classes for accessing endpoints
#import <OpenAPIClient/OAIClass1InstanceApi.h>
#import <OpenAPIClient/OAIClass2MessagesApi.h>
#import <OpenAPIClient/OAIClass3ChatsApi.h>
#import <OpenAPIClient/OAIClass4WebhooksApi.h>
#import <OpenAPIClient/OAIClass5QueuesApi.h>
#import <OpenAPIClient/OAIClass6BanApi.h>
#import <OpenAPIClient/OAIClass7TestingApi.h>
It's recommended to create an instance of ApiClient per thread in a multi-threaded environment to avoid any potential issues.
Please follow the installation procedure and then run the following:
OAIDefaultConfiguration *apiConfig = [OAIDefaultConfiguration sharedConfig];
// Configure API key authorization: (authentication scheme: instanceId)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"instanceId"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"instanceId"];
// Configure API key authorization: (authentication scheme: token)
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"token"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//[apiConfig setApiKeyPrefix:@"Bearer" forApiKeyIdentifier:@"token"];
OAIClass1InstanceApi *apiInstance = [[OAIClass1InstanceApi alloc] init];
// Updates the QR code after its expired
[apiInstance expiryWithCompletionHandler:
^(OAIInlineResponse2002* output, NSError* error) {
if (output) {
NSLog(@"%@", output);
}
if (error) {
NSLog(@"Error: %@", error);
}
}];
All URIs are relative to https://api.chat-api.com
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 has dependencies over external libraries like UniRest. These dependencies are defined in the PodFile
file that comes with the SDK.
To resolve these dependencies, we use the Cocoapods package manager.
Visit https://guides.cocoapods.org/using/getting-started.html to setup Cocoapods on your system.
Open command prompt and type pod --version
. This should display the current version of Cocoapods installed if the installation was successful.
Using command line, navigate to the directory containing the generated files (including PodFile
) for the SDK.
Run the command pod install
. This should install all the required dependencies and create the pods
directory in your project directory.
Open the project workspace using the (messengersAPI.xcworkspace) file. Invoke the build process using Command(⌘)+B
shortcut key or using the Build
menu as shown below.
The generated code is a Cocoa Touch Static Library which can be used in any iOS project. The support for these generated libraries go all the way back to iOS 6.
The following section explains how to use the messengersAPI library in a new iOS project.
To start a new project, left-click on the Create a new Xcode project
.
Next, choose Single View Application and click Next
.
Provide Test-Project as the product name click Next
.
Choose the desired location of your project folder and click Create
.
To add this dependency open a terminal and navigate to your project folder. Next, input pod init
and press enter.
Next, open the newly created PodFile
in your favourite text editor. Add the following line : pod 'messengersAPI', :path => 'Vendor/messengersAPI'
Execute pod install
from terminal to install the dependecy in your project. This would add the dependency to the newly created test project.
Unit tests in this SDK can be run using Xcode.
First build the SDK as shown in the steps above and naivgate to the project directory and open the messengersAPI.xcworkspace file.
Go to the test explorer in Xcode as shown in the picture below and click on run tests
from the menu.