2017 © Pedro Peláez
 

library chatwork-sdk

Just a non-official SDK for Chatwork

image

wataridori/chatwork-sdk

Just a non-official SDK for Chatwork

  • Thursday, June 21, 2018
  • by wataridori
  • Repository
  • 2 Watchers
  • 8 Stars
  • 14,078 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 13 Versions
  • 15 % Grown

The README.md

Chatwork SDK for PHP

API Docs
Remember that this SDK is non-official. It may not work when Chatwork update their APIs in the feature.
(However, I will try to cover all the changes from Chatwork. If something goes wrong, please let me know)

StyleCI Build Status Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Chatwork SDK now supports Chatwork API version 2
Check the Chatwork API Document here

Requirement

  • PHP >= 5.4
  • PHP cURL

Install

You can install and manage Chatwork SDK for PHP by using Composer, (*2)

composer require wataridori/chatwork-sdk

Or add wataridori/chatwork-sdk into the require section of your composer.json file then run composer update, (*3)

Usage

Firstly, to use Chatwork API, you must register an API Key.
Pass your key to ChatworkSDK class.
ChatworkSDK::setApiKey($apiKey);

If you have problems with the SSL Certificate Verification, you can turn it off by the following setting., (*4)

// Not recommend. Only do this when you have problems with the request
ChatworkSDK::setSslVerificationMode(false);

Now you can easily use many functions to access Chatwork API Endpoints., (*5)

ChatworkSDK's Classes

ChatworkAPI: This is the class that contains base API. You can use it to send request to Chatwork and receive the response in array., (*6)

ChatworkSDK::setApiKey($apiKey);
$api = new ChatworkApi();
// Get user own information
$api->me();

// Get user own statics information
$api->getMyStatus();

// Get user rooms list
$api->getRooms();
ChatworkSDK also provides many others class that help you to work in more object oriented way.
  • ChatworkRoom: Use for store Room Information, with many functions to work with Room
  • ChatworkUser: Use for store User Information.
  • ChatworkMessage: Use for store Message Information.
ChatworkSDK::setApiKey($apiKey);
$room = new ChatworkRoom($roomId);
// The following function will return an array of ChatworkUser
$members = $room->getMembers();
foreach ($members as $member) {
    // Print out User Information
    print_r($member->toArray());
}

// Send Message to All Members in the Room
$room->sendMessageToAll('Test Message');

// Send Message to list of members in the room
$room->sendMessageToList([$member_1, $member_2], 'Another Test Message');

The 3 classes above are extended from the ChatworkBase class. ChatworkBase provides you some useful function to work with messages. You can easily build a TO message, REPLY or QUOTE message., (*7)

ChatworkSDK::setApiKey($apiKey);
$room = new ChatworkRoom($roomId);
$messages = $room->getMessages();
if ($messages & !empty($messages[0])) {
    $lastMessage = $messages[0];
    // Reset Message to null string
    $room->resetMessage();
    // Append the REPLY text to current message
    $room->appendReplyInRoom($lastMessage);
    // Append the QUOTE text to current message
    $room->appendQuote($lastMessage);
    // Append the Information Text to the current message
    $room->appendInfo('Test Quote, Reply, Info text', 'Test from Chatwork-SDK');
    // Send current message into the Room
    $room->sendMessage();
}
Check ChatworkSDK functions list here for further details and usages.

Run test

  • Create a file named config.json inside the tests/fixtures/ folder.
  • Input your API Key, and a test Room into config.json file. It should look like this:
{
  "apiKey": "YOUR-API-KEY-HERE",
  "roomId": "YOUR-TEST-ROOM-HERE"
}
  • Then run phpunit to start testing.

Contribution

View contribution guidelines here, (*8)

The Versions

21/06 2018

dev-master

9999999-dev

Just a non-official SDK for Chatwork

  Sources   Download

GPL-3.0

by Tran Duc Thang

21/06 2018

0.3.0

0.3.0.0

Just a non-official SDK for Chatwork

  Sources   Download

GPL-3.0

by Tran Duc Thang

02/02 2017

0.1.8

0.1.8.0

Just a non-official SDK for Chatwork

  Sources   Download

GPL-3.0

by Tran Duc Thang

02/02 2017

0.2.1

0.2.1.0

Just a non-official SDK for Chatwork

  Sources   Download

GPL-3.0

by Tran Duc Thang

02/02 2017

0.2.0

0.2.0.0

Just a non-official SDK for Chatwork

  Sources   Download

GPL-3.0

by Tran Duc Thang

14/06 2016

0.1.7

0.1.7.0

Just a non-official SDK for Chatwork

  Sources   Download

GPL-3.0

by Tran Duc Thang

05/02 2016

0.1.6

0.1.6.0

Just a non-official SDK for Chatwork

  Sources   Download

GPL-3.0

by Tran Duc Thang

19/10 2015

0.1.5

0.1.5.0

Just a non-official SDK for Chatwork

  Sources   Download

GPL-3.0

by Tran Duc Thang

30/05 2015

v0.1.4

0.1.4.0

Just a non-official SDK for Chatwork

  Sources   Download

GPL-3.0

by Tran Duc Thang

25/04 2015

v0.1.3

0.1.3.0

Just a non-official SDK for Chatwork

  Sources   Download

GPL-3.0

by Tran Duc Thang

21/02 2015

v0.1.2

0.1.2.0

Just a non-official SDK for Chatwork

  Sources   Download

GPL-3.0

by Tran Duc Thang

21/02 2015

v0.1.1

0.1.1.0

Just a non-official SDK for Chatwork

  Sources   Download

GPL-3.0

by Tran Duc Thang

16/02 2015

v0.1.0

0.1.0.0

Just a non-official SDK for Chatwork

  Sources   Download

GPL-3.0

by Tran Duc Thang