Access your Slack Team's API through PHP objects.

Overview

Slack API library Software License

Access your Slack Team's API through PHP objects.

Build Status Coverage Status Quality Score Latest Version Total Downloads

Documentation

  • Getting started - Before you use this library, you need to generate a token or setup oAuth.
  • Installation - Information on installing this library through composer or as a git submodule.
  • Usage - A few simple examples on how to access the Slack API using this library
  • API methods - Detailed information on each of Slack's API methods and how to access them using this library's Payload classes.
  • Events - Examples for listening to events fired by the ApiClient

Features

  • Access all of Slack's API methods with dedicated payload classes (see usage documentation)
  • Payloads and responses follow the same definitions as described in the official documentation (with a few exceptions where I think it would make a better distinction).
  • Data between you and Slack is serialized using the JMS Serializer package, allowing fully spec-ed PHP objects to be used for working with the API.
  • Code has been highly abstracted to support re-use in more specific implementations (see SlackBundle)

Further reading

I've done my best to include links to the official documentation in the code where appropriate.

Still, you should really check out the API documentation of Slack yourself to get a better understanding of exactly what each API method does and what data it will return.

If you feel there is some part of this package that you would like to see documented in more detail, please don't hesitate to create an issue for it.

Contributing

Got a good idea for this project? Found a nasty bug that needs fixing? That's great! Before submitting your PR though, make sure it complies with the contributing guide to speed up the merging of your code.

Missing methods

The following methods have not yet been implemented, why not contribute and add some yourself?

  • files.delete*
  • pins.add
  • pins.list
  • pins.remove
  • reactions.add
  • reactions.get
  • reactions.list
  • reactions.remove
  • team.accessLogs
  • team.info

* = issue/PR has been opened for this method

Related packages

  • Slack CLI - CLI application for all of the Slack API methods.
  • SlackBundle - Symfony Bundle providing integration with this library package.

Attributions

  • The Slack staff, for making an awesome product and very clean API documentation.

FAQ

Why am I getting a cURL 60 error when attempting to connect to the Slack API?

Under the hood this library uses Guzzle to connect to the Slack API, and Guzzle's default method for sending HTTP requests is cURL.

The full error code is CURLE_SSL_CACERT: Peer certificate cannot be authenticated with known CA certificates and may be due, especially on Windows or OS X, to Guzzle not being able to find an up to date CA certificate bundle on the operating system.

To fix this you first create the Guzzle client manually using an alternative CA cert bundle, or disabling peer verification (not recommended for security reasons), and pass it to the API Client.

$client = new \GuzzleHttp\Client();
$client->setDefaultOption('verify', 'C:\Program Files (x86)\Git\bin\curl-ca-bundle.crt');

// continue as normal, using the client above

$apiClient =  new ApiClient('api-token-here', $client);

If you get a different error code you can look at the list of cURL error codes, or consult the Guzzle documentation directly.

Comments
  • Unable to set custom bot as message sender

    Unable to set custom bot as message sender

    Using the ChatPostMessagePayload, I am unable to set the bot I've created as the sender. I'm setting the username of a bot I've created as the username, but messages are still posted as the slackbot. I can see from the documentation that the API supports an as_user parameter which might be useful since I'm authenticating with the API token of the bot, but it appears that the repository does not support this.

    opened by nmeirik 12
  • Exception thrown when trying to send message

    Exception thrown when trying to send message

    Fatal error: Uncaught exception 'Doctrine\Common\Annotations\AnnotationException' with message '[Semantical Error] The annotation "@JMS\Serializer\Annotation\Type" in property CL\Slack\Payload\ChatPostMessagePayload::$channel does not exist, or could not be auto-loaded.' in [...path...]/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:54
    Stack trace:
    #0 [...path...]/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(708): Doctrine\Common\Annotations\AnnotationException::semanticalError('The annotation ...')
    #1 [...path...]/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(641): Doctrine\Common\Annotations\DocParser->Annotation()
    #2 [...path...]/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php(334): Doctrine\Common\Annotations\DocParser->Annotations()
    #3 [...path...]/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.p in [...path...]/vendor/cleentfaar/slack/CL/Slack/Transport/ApiClient.php on line 108
    

    I have confirmed that the Type.php file is there in the right location and the right namespace, and composer can load it through its autoloader - however the Doctrine Annotations library bypasses the standard PHP autoloading mechanism for some reason, and you have to register annotations with the AnnotationRegistry. I'm sure the JMSSerializer library must have done this, and 'use'ing the namespace and aliasing it as you are doing in ChatPostMessagePayload is supposed to fix this (use JMS\Serializer\Annotation as Serializer), so I'm unsure why this is happening myself. I'm not very familiar with the JMS Serializer library though.

    opened by chrisemerson 9
  • Update documentation in line with 013.x

    Update documentation in line with 013.x

    Firstly, your library looks great and I am looking forward to using it.

    Could you possibly update your usage documentation in line with your latest changes?

    I've tried to get up and running but am getting stuck with:

    Catchable fatal error: Argument 2 passed to CL\Slack\Transport\ApiClient::__construct() must be an instance of CL\Slack\Util\PayloadSerializer, none given, called in C:\inetpub\wwwroot\src\SD\SOS\Console\Check.php on line 19 and defined in C:\inetpub\wwwroot\vendor\cleentfaar\slack\src\CL\Slack\Transport\ApiClient.php on line 78
    

    I can see that you've added a PayloadSerializer param to ApiClient but can't seem to pass it the right thing.

    e.g. I've tried:

    $payloadSerialiazer = new \CL\Slack\Util\PayloadSerializer();
    $client = new \CL\Slack\Transport\ApiClient($apiToken, $payloadSerializer);
    

    But no luck.

    You also give the example of $payload->setMessage(), but this is depreciated in favour of $payload->setText()?

    opened by deancsmith 7
  • Failed to send payload with guzzlehttp/guzzle >6.0.0

    Failed to send payload with guzzlehttp/guzzle >6.0.0

    After running compose update guzzlehttp/guzzle package got updated to 6.0.1 and effectively broke sending messages. I fixed it by fixing it at version 5.3.0 in my composer.json.

    I don't know what has changed in guzzle package but you have to restrict it to version below 6.0.0 or make it compatible with new version.

    opened by AndrzejFR 6
  • Adding subtype and attachments to SimpleMessage

    Adding subtype and attachments to SimpleMessage

    Documentation for the added properties: https://api.slack.com/events/message

    Subtype

    Unlike other event types, message events can have a subtype

    Attachments

    Messages can also include an attachments property, containing a list of attachment objects. https://api.slack.com/docs/attachments

    opened by solomonjames 3
  • Symfony Yaml Library Inclusion

    Symfony Yaml Library Inclusion

    @cleentfaar: Resolves #11

    Although there may be an issue with an included library not correctly declaring their own dependencies, friction can and should be reduced for users of the "cleentfaar/slack" package by masking them from this problem and taking the issue up separately with any maintainers of the underlying dependency libraries.

    Wonderful library you have - thanks for considering the patch!

    opened by jimdelois 3
  • Major refactoring (removed dependency on annotations, completed tests)

    Major refactoring (removed dependency on annotations, completed tests)

    This removes the dependency on annotations for serialization of objects (now using yaml mapping).

    I've also added almost all of the tests that were (still) missing, and fixed a lot of hidden bugs.

    todo:

    • [x] Stamp out as much bugs as possible
    • [x] Add the (missing) tests for all payloads and responses
    • [x] Add the missing tests for the models
    opened by cleentfaar 3
  • Post Message as User

    Post Message as User

    I have oAuth2 working and would like to post a message as an authenticated user.

    Would like to try and patch this myself but at a loss as where to get started.

    opened by raupie 2
  • Deserializing messages fixed

    Deserializing messages fixed

    When you called the messages.search API method, the JMS serializer throw an error "you should define a type of permalink". So I fixed that and every error which occurred later.

    bug question 
    opened by piotrpasich 2
  • nested message payload not correctly serialized

    nested message payload not correctly serialized

    method used: chat.postMessage

    When I try to post a message with attachments, the attachments are not 'seen' by the slack service. I tried encoding them to json prior to sending them to slack via a guzzle event listener like this:

    $guzzle->getEmitter()->on('before', function (BeforeEvent $before) {
        $body = $before->getRequest()->getBody();
        $attachments = $body->getField('attachments');
        $body->setField('attachments', json_encode($attachments));
    });
    

    And got what I expected (a chat message with attachments). However, this leads me to think there is something wrong with the serialization process of nested payload entries.

    In short, my findings:

    //does not work
    [
        'attachments' => [
            ['title' => 'hello world']
        ]
    ]
    
    //does work
    [
        'attachments' => "[{'title': 'hello world'}]"
    ]
    
    opened by eelkevdbos 2
  • What is the purpose of ModelSerializer?

    What is the purpose of ModelSerializer?

    Hi Cas,

    I noticed that the CL\Slack\Serializer\ModelSerializer class is never integrated in the library. It exists, but none of the other parts are calling it. Except for the AbstractModelTest class which uses it to test the getters of the models.

    I was wondering if you plan to use it in the library or if it's merely there for testing purposes.

    Thx!

    Matthias

    opened by netsensei 2
  • Support Laravel 5.7 (symfony event dispatcher)

    Support Laravel 5.7 (symfony event dispatcher)

    • Installation request for cleentfaar/slack ^0.20.1 -> satisfiable by cleentfaar/slack[0.20.1].
    • Conclusion: remove symfony/event-dispatcher v4.1.6
    • Conclusion: don't install symfony/event-dispatcher v4.1.6

    laravel_5_7

    opened by glorand 0
  • How to detect messages by Slack?

    How to detect messages by Slack?

    How can I detect messages such as "xy has joined the channel", "xy set the channel purpose", and similar, which are not really composed by a person but rather Slack? Unfortunately, the username and userId given in SimpleMessage are the same, no matter if its a message from a human being or Slack in the name of the human being. Is there a sensible way to detect what kind of message it is?

    opened by GenieTim 1
  • Incorrect field mapping for `initialComment`

    Incorrect field mapping for `initialComment`

    This is mapped as a string but is actually returned as an object from Slack and causes the deserialisation of the API response to throw a SlackException exception with the message "Array to string conversion".

    https://github.com/cleentfaar/slack/blob/ba7073cb79ccea423cd68f6a69096384a730a013/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.File.yml#L82

    initial_comment is actually this format:

    {id: "Fc80KCQ5MF",
    created: 1510793564,
    timestamp: 1510793564,
    user: "U8167JE7P",
    is_into: true,
    comment: "Blah blah blah"
    }
    
    opened by mikeymclellan 0
  • 'missing_scope' error handling

    'missing_scope' error handling

    Added properties to the abstract class of response payload for scope that needed to complete the requested method and scopes that provided by application. Added explanation for error 'missing_scope' that includes details about needed scope and scopes, provided by the application.

    opened by pshentsoff 1
  • Support Symfony 4

    Support Symfony 4

    Hi @cleentfaar

    The Yaml dependency appears to be fixed under 3.0, and hence I cannot port a bundle I'm working on to Symfony 4 :)

    Would you mind to add this support?

    Thank you

    opened by pierre-tranchard 0
Releases(0.20.1)
The library provides convenient access to the Epoint.az API from applications written in the PHP language.

Tural/Epoint library/SDK The library provides convenient access to the Epoint.az API from applications written in the PHP language. It includes a pre-

Tural 5 Jan 20, 2022
The library provides convenient access to the Epoint.az API from applications written in the PHP language.

Tural/Epoint library/SDK The library provides convenient access to the Epoint.az API from applications written in the PHP language. It includes a pre-

Tural 5 Jan 20, 2022
This app remembers todo list in every specified time (e. every minute, hour, day etc) through telegram bot

remember_todo_list This app remembers todo list in every specified time (e. every minute, hour, day etc) through telegram bot This project includes tw

Saidburxon 1 Nov 27, 2021
Nexmo REST API client for PHP. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.

Client Library for PHP Support Notice This library and it's associated packages, nexmo/client and nexmo/client-core have transitioned into a "Maintena

Nexmo 75 Sep 23, 2022
OpenAI API Client is a component-oriented, extensible client library for the OpenAI API. It's designed to be faster and more memory efficient than traditional PHP libraries.

OpenAI API Client in PHP (community-maintained) This library is a component-oriented, extensible client library for the OpenAI API. It's designed to b

Mounir R'Quiba 6 Jun 14, 2023
Integrate Your PHP Code With Telegram Bot API for Beginner

Documentation[https://core.telegram.org/bots/api] Resource[https://github.com/bachors/KBBI.sql] Integrate Your PHP Code With Telegram Bot API for Begi

Nova Andre Saputra 1 Oct 19, 2021
DigitalOcean API v2 client for Symfony and API Platform

DigitalOcean Bundle for Symfony and API Platform DunglasDigitalOceanBundle allows using the DigitalOcean API from your Symfony and API Platform projec

Kévin Dunglas 25 Jul 27, 2022
This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

Daniel Henze 3 Aug 29, 2022
API SDK for OpenTrade Commerce API: Taobao, Alibaba, JD, 1688, Aliexpress, Ebay.

OtapiPhpClient Create Client $client = new OtClient($key, $secret, $lang); key (Access Key) secret (Secret for access key) language (2 symbol lang id

OpenTrade Commerce 5 Sep 20, 2022
Fanmade project using Twitter API and Marvel API.

Project Marvel Memories A fanmade project in PHP using API Twitter V2, Marvel API and Github action scheduler. What about? Posts a random cover with d

Julien SCHMITT 15 Dec 17, 2022
API client for ThePay - payment gate API

This is the official highly compatible public package of The Pay SDK which interacts with The Pay's REST API. To get started see examples below.

ThePay.cz s.r.o. 3 Oct 27, 2022
Code Quiz MonoRepo (API, API Client, App)

Code Quiz Welcome to the Code Quiz Open Source project from How To Code Well. This is an Open Source project that includes an API and an App for the d

How To Code Well 2 Nov 20, 2022
This package help you build your REST API documentation.

Laravel API Doc This package help you build your REST API documentation. Installation You can install the package via composer: composer require axeld

Axel 2 May 19, 2022
Embed live members' count from all your Discord server in your WordPress website

Live Members Counter For Discord This is the repository for the WordPress plugin: Live Members Counter for Discord Live Members Counter For Discord is

null 1 Oct 30, 2021
⚡️ Web3 PHP is a supercharged PHP API client that allows you to interact with a generic Ethereum RPC.

Web3 PHP is a supercharged PHP API client that allows you to interact with a generic Ethereum RPC. This project is a work-in-progress. Code and docume

Web3 PHP 665 Dec 23, 2022
Lightweight PHP library for WhatsApp API to send the whatsapp messages in PHP provided by ultramsg.com

Ultramsg.com WhatsApp API PHP SDK Lightweight PHP library for WhatsApp API to send the whatsappp messages in PHP provided by Ultramsg.com Installation

Ultramsg 117 Dec 26, 2022
Google-api-php-client - A PHP client library for accessing Google APIs

Google APIs Client Library for PHP Reference Docs https://googleapis.github.io/google-api-php-client/main/ License Apache 2.0 The Google API Client Li

Google APIs 8.4k Dec 30, 2022
Wise-php - This library is written to accommodate the wise API's use in php projects With Wise

Wise-php - This library is written to accommodate the wise API's use in php projects With Wise you can automate payments, connect your business tools, and create ways to manage your finances. You can also power your cross-border and domestic payouts.

Albert Xhani 15 Nov 17, 2022
PHP library for the Stripe API.

Stripe PHP bindings The Stripe PHP library provides convenient access to the Stripe API from applications written in the PHP language. It includes a p

Stripe 3.3k Jan 5, 2023