jclg / php-slack-bot Goto Github PK
View Code? Open in Web Editor NEWSlack bot user written in PHP
License: MIT License
Slack bot user written in PHP
License: MIT License
I found article in slack documentation (https://api.slack.com/docs/message-attachments) about attachments, and i have to ask, can your bot do this?
Is there documentation anywhere about what possible information might come back as $data?
Current implemenation of Command is case-sensitive. E.g. if I register a command help
, I should send exact command help
, but not Help
or HELP
. It's unusual.
So, why don't make it case-insensitive by adding modifier i
inside getCommand
method?
This
$find = '/^'.preg_quote($commandName).'/';
Change to this
$find = '/^'.preg_quote($commandName).'/i';
Hi,
I've been playing around with php-slack-bot and I like it so far. However, I have a question I would like to ask : is there any way to respond to a user running a command in a public channel by direct message ?
Thanks,
David
I have been trying to debug but got no results. Bot is successfully getting wsurl but I think it is not connecting to the wsurl (No log indicating it has connected), also it does not respond to any command. Also the php script terminates after around 30 seconds of run time. What might be the problem ?
Installing of this package requires setting minimum stability to "dev". This is not good idea if you package is stable enough. This setting is global. But I don't want any other packages to be installed with dev-stability level. It should be better if you require dev package as following:
"require": {
"devristo/phpws": "dev-master@dev",
"react/http": "^0.4"
},
This will not require global minimum stability set to "dev".
In theory, I should be able to send links using the format <http://example.com|Name of site>
which is supposed to turn into a hyperlink with my chosen text to the provided URL. (See https://api.slack.com/docs/message-formatting - which is linked from the RTM API docs page under "formatting messages".)
In practice, this is displaying exactly as is. It seems that the string is getting encoded somewhere (e.g. <
becomes <
), but I can't for the life of me find what's doing this in your source. Any tips on tracking this down and/or bypassing it?
I guess it's version issue
The process ends when message $data->type is "team_migration_started". See https://api.slack.com/events/team_migration_started. Any way to keep the process alive in this event?
plz remove this issue, i've made pull request instead
Is there a way to get the bot to only run commands when mentioned? Is adding the bots username to the command name enough?
ie instead of just typing doThing
in slack I want to have to type @mybot doThing
C:\xampp\htdocs\slackbot>php example1.php 2016-07-27T17:13:47+02:00 NOTICE (5): Request object created! 2016-07-27T17:13:47+02:00 NOTICE (5): Handshake received! 2016-07-27T17:13:47+02:00 NOTICE (5): Connected! 2016-07-27T17:13:48+02:00 NOTICE (5): Got message: {"type":"hello"} 2016-07-27T17:13:48+02:00 NOTICE (5): Got message: {"type":"reconnect_url","url":"wss://mpmulti-uh6j.slack-msgs.com/websocket/<removed>="} 2016-07-27T17:13:48+02:00 NOTICE (5): Got message: {"type":"presence_change","presence":"active","user":"U1XXXXX"} 2016-07-27T17:14:00+02:00 NOTICE (5): Got message: {"type":"reconnect_url","url":"wss://mpmulti-9bvx.slack-msgs.com/websocket/<removed>="}
Issue:
Bot not joining default channel #general, can't interact with him. Also, in https://my.slack.com/services/new/bot:
http://i.imgur.com/nfVwaGU.png
Slack has sent out a recent deprecation notice for rtm.start - The timeline is;
November 30, 2021 - New Slack apps and integrations will no longer be able to use rtm.start and must use rtm.connect instead.
September 20, 2022 - The response from rtm.start will transform into the brief response found in the method that replaces it, rtm.connect.
Hello,
Not an issue but a addition I made. This is a fallback command that will be executed when no command is found. Sort of like a catch-all command, but loaded commands will be executed first. I don't know much how this pull request thing work so here it is, as a patch file for Bot.php :
14d13
< private $fallBackCommand = null;
38,46d36
< public function loadFallBackCommand($command) {
< if ($command instanceof Command\BaseCommand) {
< $this->fallBackCommand = $command;
< }
< else {
< throw new \Exception('Command must implement PhpSlackBot\Command\BaseCommand');
< }
< }
<
205,207d194
< }
< if (null !== $this->fallBackCommand) {
< return $this->fallBackCommand;
Usage :
require 'vendor/autoload.php';
use PhpSlackBot\Bot;
// This special command executes when no command is found
class FallBackCommand extends \PhpSlackBot\Command\BaseCommand {
protected function configure() {
// We don't have to configure a command name in this case
}
protected function execute($data, $context) {
if ($data['type'] == 'message') {
$channel = $this->getChannelNameFromChannelId($data['channel']);
$username = $this->getUserNameFromUserId($data['user']);
echo $username.' from '.($channel ? $channel : 'DIRECT MESSAGE').' : '.$data['text'].PHP_EOL;
}
}
}
$bot = new Bot();
$bot->setToken('TOKEN'); // Get your token here https://my.slack.com/services/new/bot
$bot->loadFallBackAllCommand(new FallBackCommand());
$bot->run();
Hopefully there will be no bug in this code...
Hi, could you include a way of instructing the bot to leave a particular channel.
(when i started the bot it joined a channel wich i did not want it to join ... )
Regards.
Sam
@jclg, Is there any way to not show the user's command? For example, in planing poker the vote is not interesting to show to everyone in the group.
I was wondering if the bot is able to send to a channel without any user command. For example the within my application something happens, I want the bot to post some data.
Hello @jclg
I have installed this library into my application (using composer) but I do not know where to go now! I have replaced the token given to me by Slack (a bot token). I am not sure how to make the app listen for incoming connections.
Sorry if that sounds like a newbie question.
Multiple catch all commands would be nice. We have a couple bots that do regex on messages.
The bot loses connection sometimes and does nothing with it. In slack chat (web-)application slackbot user just become with gray circle (offline). But the script continues to run, need to be killed and restarted. Isn't there a way to force the bot to check is connection alive and throw an exception if not?
The code (excepting code of commands and config):
<?php
require __DIR__ . '/vendor/autoload.php';
use PhpSlackBot\Bot;
use SlackBot\Commands\AlphaLockCommand;
use SlackBot\Commands\AlphaShipmentCommand;
use SlackBot\Commands\GetItemQtyCommand;
use SlackBot\Commands\StatusCommand;
$config = require __DIR__ . '/config.php';
$bot = new Bot();
$bot->setToken($config['slackbot']['token']);
try {
$bot->loadCommand(new StatusCommand());
$bot->loadCommand(new GetItemQtyCommand());
$bot->loadCommand(new AlphaLockCommand());
$bot->loadCommand(new AlphaShipmentCommand());
$bot->run();
} catch (\Exception $e) {
echo $e->getMessage(), "\n";
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.