public function onMention(Message $message, ChannelInterface $channel, User $user) { if ($message->matchesAny('/hello/i', '/greetings/i')) { $greetings = sprintf('%s, %s!', $this->greeting, $user->getUsername()); $this->bot->say($greetings, $channel); } }
/** * Connect to slack server */ protected function connect() { $this->client->connect()->then(function () { return $this->client->getAuthedUser(); })->then(function (User $user) { $this->botUser = $user; $this->logger->info("Connected as " . $this->botUser->getUsername()); }); }
/** * Welcomes a user to the team. * * @param array $data Event data. */ protected function welcomeUser(User $user) { // Open a DM with the user and talk about the Slack team a bit. $this->client->getDMbyUserId($user->getId())->then(function (DirectMessageChannel $channel) { return $this->client->getDMById($channel->getId()); })->then(function (DirectMessageChannel $channel) use($user) { return $this->client->send(sprintf("Hi there, %s! Thanks for signing up! I'm sure my friend <@USLACKBOT> is helping you set up your account right now.", $user->getUsername()), $channel)->then(function () use($user, $channel) { sleep(3); return $this->client->send("I just want to informally introduce you to the team." . " First, you will see a list of channels on the left. There's the <#C025YTX9D>" . " channel, which is a great place to discuss normal goings-on. If you want to just" . " hang out and talk about random things, the <#C025YTX9F> channel is perfect for that.", $channel); })->then(function () use($user, $channel) { sleep(6); return $this->client->send("If you're looking to start a group project, private groups are" . " perfect for that. You can create a new group by clicking on the \"+\" next to \"PRIVATE" . " GROUPS\" on the left.", $channel); })->then(function () use($user, $channel) { sleep(5); return $this->client->send("If you have any questions, feel free to ask one of the humans in <#C025YTX9D>.", $channel); }); }); }
/** * Messaging helper. Sends message to last message channel with sender username mentioning. * * @param $message */ public function reply($message) { $this->bot->say(sprintf('%s, %s', $this->lastMessageUser->getUsername(), $message), $this->lastMessageChannel); }
public function testUsername() { $username = $this->faker->userName; $user = new User($this->client, ['name' => $username]); $this->assertEquals($username, $user->getUsername()); }