Skip to content

Chertovsky/whatsapp-chatapi-sdk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Chat-API.com SDK

Simple class makes work with chat-api.com easier

Create instance

  $api = new ChatApi(
        '_token_', // Chat-Api.com token
        'https://foo.chat-api.com/instance1234' // Chat-Api.com API url
  );

Get QR code

Server example:

if(isset($_GET['qr']) {
  header('Content-Type: image/png');
  readfile( $api->getQRCode() );
}

Client example:

  

  <script>
  $.get('index.php', {'qr': '1'}, function(i) {
      switch(i)
      {
          case 'init':
              text = 'Клиент не инициализирован';
              break;

          case 'error':
              text = 'Ошибка: Chat-Api не отвечает';
              break;

          case 'loading':
              text = 'Идёт загрузка с WhatsApp';
              break;

          case 'got qr code':
              text = 'Получен QR-код';
              $('#qrcode')[0].src = 'index.php?act=qr';
              break;

          case 'authenticated':
              text = 'Онлайн';
              break;
      }

      alert(text);
  });
</script>

Send message

	die(
		($api->sendPhoneMessage('+12345', 'It works!') == true) ? 'Message sent' : 'Fail'
	);

About

SDK for Chat-Api.com

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%