- Saved searches
- Use saved searches to filter your results more quickly
- drdim/chat-api-com
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- Chat API PHP SDK for messengers API
- Preparatory work
- Development of messengers Chat Bot. Full manual
- The first steps for beginners
- [For Windows Users Only] Configuring CURL Certificate Path in php.ini
- How to Use
- 1. Open Project in an IDE
- 2. Add a new Test Project
- 3. Run the Test Project
- How to Test
- Other messengers API SDKs
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
drdim/chat-api-com
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
The REST API allows you to receive and send messages through your WhatsApp 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 WhatsApp API is based on the WhatsApp 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 WhatsApp after several clicking the «block» button.
This PHP package is automatically generated by the Swagger Codegen project:
This package modify by drdim (fix bugs)
To install the bindings via Composer, add the following to composer.json :
Then run composer install
Download the files and include autoload.php :
require_once('/path/to/chat-api-com/vendor/autoload.php');
composer install ./vendor/bin/phpunit
Please follow the installation procedure and then run the following:
require_once(__DIR__ . '/vendor/autoload.php'); // Configure API key authorization: token $config = ChatApiCom\Client\Configuration::getDefaultConfiguration() ->setApiKey('token', 'YOUR_API_KEY') // from LK ->setInstanceId('YOUR_INSTANCE_ID'); // from LK $apiInstance = new ChatApiCom\Client\Api\BanApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. new GuzzleHttp\Client(), $config ); $body = new \ChatApiCom\Client\Model\BanTestAction(); // \ChatApiCom\Client\Model\BanTestAction | $phone pl-s">phone_example"; // string | try < $result = $apiInstance->banTest($body$phone); print_r($result); > catch (Exception $e) < echo 'Exception when calling BanApi->banTest: ', $e->getMessage(), PHP_EOL; > ?>
Documentation for API Endpoints
All URIs are relative to ://api.chat-api.com/instance
Class | Method | HTTP request | Description |
---|---|---|---|
BanApi | banTest | POST /banTest | Test ban settings |
BanApi | getBanSettings | GET /banSettings | Get settings |
BanApi | setBanSettings | POST /banSettings | Set settings |
ChatsApi | addGroupParticipant | POST /addGroupParticipant | Adding a participant to a group |
ChatsApi | creatGroup | POST /group | Creates a group and sends the message to the created group. |
ChatsApi | getChats | GET /dialogs | Get the chat list. |
ChatsApi | readChat | POST /readChat | Open chat for reading messages |
InstanceApi | getQRCode | GET /qr_code | Direct link to QR-code in the form of an image, not base64. |
InstanceApi | getSettings | GET /settings | Get settings |
InstanceApi | getStatus | GET /status | Get the account status and QR code for authorization. |
InstanceApi | logout | POST /logout | Logout from WhatsApp Web to get new QR code. |
InstanceApi | reboot | POST /reboot | Logout from WhatsApp Web to get new QR code. |
InstanceApi | setSettings | POST /settings | Set settings |
MessagesApi | forwardMessage | POST /forwardMessage | Forwarding messages to a new or existing chat. |
MessagesApi | getMessages | GET /messages | Get a list of messages. |
MessagesApi | sendContact | POST /sendContact | Sending a contact or contact list to a new or existing chat. |
MessagesApi | sendFile | POST /sendFile | Send a file to a new or existing chat. |
MessagesApi | sendLink | POST /sendLink | Send text with link and link’s preview to a new or existing chat. |
MessagesApi | sendLocation | POST /sendLocation | Sending a location to a new or existing chat. |
MessagesApi | sendMessage | POST /sendMessage | Send a message to a new or existing chat. |
MessagesApi | sendPTT | POST /sendPTT | Send a ptt-audio to a new or existing chat. |
MessagesApi | setWebhook | POST /webhook | Sets the URL for receiving webhook notifications of new messages and message delivery events (ack). |
MessagesQueueApi | clearMessagesQueue | POST /clearMessagesQueue | clearMessagesQueue |
MessagesQueueApi | showMessagesQueue | GET /showMessagesQueue | Get outbound messages queue. |
- AddGroupParticipantAction
- AddGroupParticipantStatus
- Ask
- BanSettings
- BanTestAction
- BanTestStatus
- Chat
- ChatIdProp
- ChatUpdate
- Chats
- ClearMessagesQueueStatus
- CreateGroupAction
- CreateGroupStatus
- ForwardMessageRequest
- InlineResponse200
- InlineResponse2001
- InlineResponse401
- InstanceStatus
- Message
- Messages
- OutboundMessage
- OutboundMessages
- PhoneProp
- ReadChatAction
- ReadChatStatus
- SendContactRequest
- SendFileRequest
- SendLinkRequest
- SendLocationRequest
- SendMessageRequest
- SendMessageStatus
- SendPTTRequest
- SetWebhookStatus
- Settings
- WebhookUrl
Documentation For Authorization
Chat API PHP SDK for messengers API
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.
Preparatory work
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.
Development of messengers Chat Bot. Full manual
We’ve written the most comprehensive guide on how to create a simple PHP bot using the messengers API
The first steps for beginners
The generated code has dependencies over external libraries like UniRest. These dependencies are defined in the composer.json file that comes with the SDK. To resolve these dependencies, we use the Composer package manager which requires PHP greater than 5.3.2 installed in your system. Visit https://getcomposer.org/download/ to download the installer file for Composer and run it in your system. Open command prompt and type composer —version . This should display the current version of the Composer installed if the installation was successful.
- Using command line, navigate to the directory containing the generated files (including composer.json ) for the SDK.
- Run the command composer install . This should install all the required dependencies and create the vendor directory in your project directory.
[For Windows Users Only] Configuring CURL Certificate Path in php.ini
CURL used to include a list of accepted CAs, but no longer bundles ANY CA certs. So by default it will reject all SSL certificates as unverifiable. You will have to get your CA’s cert and point curl at it. The steps are as follows:
- Download the certificate bundle (.pem file) from https://curl.haxx.se/docs/caextract.html on to your system.
- Add curl.cainfo to your php.ini file located in your php installation. “PATHTO” must be an absolute path containing the .pem file.
[curl]; A default value for the CURLOPT_CAINFO option. This is required to be an ; absolute path. curl.cainfo = PATH_TO/cacert.pem
How to Use
The following section explains how to use the messengersAPI library in a new project.
1. Open Project in an IDE
Open an IDE for PHP like PhpStorm. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.
Click on Open in PhpStorm to browse to your generated SDK directory and then click OK .
2. Add a new Test Project
Create a new directory by right clicking on the solution name as shown below:
Name the directory as «test»
Add a PHP file to this project
Depending on your project setup, you might need to include composer’s autoloader in your PHP code to enable auto loading of classes.
require_once "../vendor/autoload.php";
It is important that the path inside require_once correctly points to the file autoload.php inside the vendor directory created during dependency installations.
After this 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.
3. Run the Test Project
To run your project you must set the Interpreter for your project. Interpreter is the PHP engine installed on your computer.
Open Settings from File menu.
Select PHP from within Languages & Frameworks
Browse for Interpreters near the Interpreter option and choose your interpreter.
Once the interpreter is selected, click OK
To run your project, right click on your PHP file inside your Test project and click on Run
How to Test
Unit tests in this SDK can be run using PHPUnit.
- First install the dependencies using composer including the require-dev dependencies.
- Run vendor\bin\phpunit —verbose from commandline to execute tests. If you have installed PHPUnit globally, run tests using phpunit —verbose instead.
You can change the PHPUnit test configuration in the phpunit.xml file.
Other messengers API SDKs
You can configure the SDK or generate other SDKs in 30+ programming languages: Chat API SDK generator.