GithubHelp home page GithubHelp logo

cleentfaar / slack Goto Github PK

View Code? Open in Web Editor NEW
76.0 10.0 67.0 3.53 MB

Access your Slack Team's API through PHP objects.

Home Page: http://cleentfaar.github.io/slack

License: MIT License

PHP 100.00%

slack's Introduction

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.

slack's People

Contributors

adrienbrault avatar agentsib avatar arendjantetteroo avatar ballisticpain avatar carsso avatar cleentfaar avatar hashnz avatar mathielen avatar n1c avatar nousefreak avatar nyholm avatar salt-lick avatar stefanbraspenning avatar zxurian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slack's Issues

Add accessors for Attachments in SimpleMessage Class

even though attachments are included in the simple message model, I don't see any straightforward way of getting at those so I propose just adding a simple accessor method for them to this class instead.

PR to follow.

IM Channels returning Null

Attempting to get an authenticated users ImChannels via the ImListPayload class. The getImChannels() response returns null.

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".

initial_comment is actually this format:

{id: "Fc80KCQ5MF",
created: 1510793564,
timestamp: 1510793564,
user: "U8167JE7P",
is_into: true,
comment: "Blah blah blah"
}

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.

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()?

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'}]"
]

Added cleentfar/slack via composer, and got exception when trying to send payload

looks like that you include jms/serializer as a dependency, but jms/serializer then tries to make a call to symfony yaml, which I didn't have installed.
Installing symfony/yaml separately removed the exception and everything works now, however you might want to include symfony/yaml as a dependency for this in composer.

Fatal error: Class 'Symfony\Component\Yaml\Yaml' not found in /var/www/tantornet/vendor/jms/serializer/src/JMS/Serializer/Metadata/Driver/YamlDriver.php on line 35
Call Stack
#   Time    Memory  Function    Location
1   0.0000  238112  {main}( )   ../index.php:0
2   0.0241  2396088 Zend\Mvc\Application->run( )    ../index.php:12
3   0.0249  2427496 Zend\EventManager\EventManager->trigger( )  ../Application.php:313
4   0.0249  2427496 Zend\EventManager\EventManager->triggerListeners( ) ../EventManager.php:207
5   0.0250  2429256 call_user_func:{/var/www/tantornet/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:468} ( )   ../EventManager.php:468
6   0.0250  2429752 Zend\Mvc\DispatchListener->onDispatch( )    ../EventManager.php:468
7   0.0283  2804240 Zend\Mvc\Controller\AbstractController->dispatch( ) ../DispatchListener.php:113
8   0.0283  2804704 Zend\EventManager\EventManager->trigger( )  ../AbstractController.php:116
9   0.0283  2804704 Zend\EventManager\EventManager->triggerListeners( ) ../EventManager.php:207
10  0.0285  2816280 call_user_func:{/var/www/tantornet/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:468} ( )   ../EventManager.php:468
11  0.0285  2816800 Application\Mvc\Controller\TantorController->onDispatch( )  ../EventManager.php:468
12  0.0285  2816896 Zend\Mvc\Controller\AbstractActionController->onDispatch( ) ../TantorController.php:108
13  0.0285  2817136 DataSystems\Controller\IndexController->indexAction( )  ../AbstractActionController.php:83
14  0.0356  3445104 CL\Slack\Transport\ApiClient->send( )   ../IndexController.php:28
15  0.0356  3445248 CL\Slack\Serializer\PayloadSerializer->serialize( ) ../ApiClient.php:110
16  0.0356  3445520 JMS\Serializer\Serializer->serialize( ) ../PayloadSerializer.php:28
17  0.0377  3492896 JMS\Serializer\GraphNavigator->accept( )    ../Serializer.php:91
18  0.0384  3507024 Metadata\MetadataFactory->getMetadataForClass( )    ../GraphNavigator.php:180
19  0.0428  3579496 Metadata\Driver\DriverChain->loadMetadataForClass( )    ../MetadataFactory.php:103
20  0.0428  3579496 Metadata\Driver\AbstractFileDriver->loadMetadataForClass( ) ../DriverChain.php:38
21  0.0428  3580528 JMS\Serializer\Metadata\Driver\YamlDriver->loadMetadataFromFile( )  ../AbstractFileDriver.php:28

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

ImOpenPayloadResponse and ImListPayloadResponse objects missing 'ims' and 'channel' info

ImListPayload:
API Response:

Array
(
    [ok] => 1
    [ims] => Array
        (
            [0] => Array
                (
                    [id] => D0HKRRWQP
                    [is_im] => 1
                    [user] => USLACKBOT
                    [created] => 1451874761
                    [is_user_deleted] => 
                )

            [1] => Array
                (
                    [id] => D0HKV684X
                    [is_im] => 1
                    [user] => U029ETG96
                    [created] => 1451885123
                    [is_user_deleted] => 
                )
        )
)

ImListPayloadResponse Object:

CL\Slack\Payload\ImListPayloadResponse Object
(
    [channels:CL\Slack\Payload\ImListPayloadResponse:private] => 
    [ok:CL\Slack\Payload\AbstractPayloadResponse:private] => 1
    [error:CL\Slack\Payload\AbstractPayloadResponse:private] => 
)

ImOpenPayload:
API Response:

Array
(
    [ok] => 1
    [no_op] => 1
    [already_open] => 1
    [channel] => Array
        (
            [id] => D0HKLBTL4
        )
)

ImOpenPayloadResponse Object:

CL\Slack\Payload\ImOpenPayloadResponse Object
(
    [noOp:CL\Slack\Payload\ImOpenPayloadResponse:private] => 1
    [alreadyOpen:CL\Slack\Payload\ImOpenPayloadResponse:private] => 1
    [ok:CL\Slack\Payload\AbstractPayloadResponse:private] => 1
    [error:CL\Slack\Payload\AbstractPayloadResponse:private] => 
)

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

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.

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.

oAuth Access Method

Error: Call to a member function send() on a non-object. My $payload variable dumps as an object so I'm not sure what I'm doing wrong.

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

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.

'Attachment model missing type definition for' errors

While testing out this library I ran into the same problems as described in #59 . However, after applying the patch from #59 locally I found that It required further modifications, the full list of additions to CL.Slack.Model.Attachment.yml that worked for me was:


        mrkdwnIn:
            type: array
        titleLink:
            type: string
        authorName:
            type: string
        authorLink:
            type: string
        authorIcon:
            type: string

PR to follow.

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.