Skip to content

Commit

Permalink
Merge branch 'master' of github.com:botman/driver-slack
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed Sep 30, 2017
2 parents 1e4c2fc + f376c81 commit 42df8a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
23 changes: 11 additions & 12 deletions src/Extensions/Dialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

abstract class Dialog
{

/** @var string */
protected $title;

Expand All @@ -15,7 +14,7 @@ abstract class Dialog

/** @var string */
protected $callbackId;

/** @var array */
protected $elements = [];

Expand Down Expand Up @@ -65,7 +64,7 @@ public function add(string $label, string $name, string $type, array $additional
public function text(string $label, string $name, $value = null, $additional = [])
{
return $this->add($label, $name, 'text', array_merge([
'value' => $value
'value' => $value,
], $additional));
}

Expand All @@ -79,7 +78,7 @@ public function text(string $label, string $name, $value = null, $additional = [
public function textarea(string $label, string $name, $value = null, $additional = [])
{
return $this->add($label, $name, 'textarea', array_merge([
'value' => $value
'value' => $value,
], $additional));
}

Expand All @@ -94,7 +93,7 @@ public function email(string $label, string $name, $value = null, $additional =
{
return $this->add($label, $name, 'text', array_merge([
'subtype' => 'email',
'value' => $value
'value' => $value,
], $additional));
}

Expand All @@ -109,7 +108,7 @@ public function number(string $label, string $name, $value = null, $additional =
{
return $this->add($label, $name, 'text', array_merge([
'subtype' => 'number',
'value' => $value
'value' => $value,
], $additional));
}

Expand All @@ -124,7 +123,7 @@ public function tel(string $label, string $name, $value = null, $additional = []
{
return $this->add($label, $name, 'text', array_merge([
'subtype' => 'tel',
'value' => $value
'value' => $value,
], $additional));
}

Expand All @@ -139,7 +138,7 @@ public function url(string $label, string $name, $value = null, $additional = []
{
return $this->add($label, $name, 'text', array_merge([
'subtype' => 'url',
'value' => $value
'value' => $value,
], $additional));
}

Expand All @@ -151,10 +150,10 @@ public function toArray()
$this->buildForm();

return [
"callback_id" => $this->callbackId,
"title" => $this->title,
"submit_label" => $this->submitLabel,
"elements" => $this->elements
'callback_id' => $this->callbackId,
'title' => $this->title,
'submit_label' => $this->submitLabel,
'elements' => $this->elements,
];
}
}
12 changes: 7 additions & 5 deletions src/SlackDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Illuminate\Support\Collection;
use BotMan\BotMan\Drivers\HttpDriver;
use BotMan\Drivers\Slack\Extensions\User;
use BotMan\Drivers\Slack\Extensions\Dialog;
use BotMan\BotMan\Messages\Incoming\Answer;
use BotMan\Drivers\Slack\Extensions\Dialog;
use BotMan\BotMan\Interfaces\VerifiesService;
use BotMan\BotMan\Messages\Attachments\Image;
use BotMan\BotMan\Messages\Outgoing\Question;
Expand Down Expand Up @@ -252,14 +252,14 @@ public function replyInThread($message, $additionalParameters, $matchingMessage,
* @param \BotMan\BotMan\Messages\Incoming\IncomingMessage $matchingMessage
* @return array
*/
public function replyDialog(Dialog $dialog, $additionalParameters = [], $matchingMessage, BotMan $bot)
public function replyDialog(Dialog $dialog, $additionalParameters, $matchingMessage, BotMan $bot)
{
$this->resultType = self::RESULT_DIALOG;
$payload = [
'trigger_id' => $this->payload->get('trigger_id'),
'channel' => $matchingMessage->getRecipient() === '' ? $matchingMessage->getSender() : $matchingMessage->getRecipient(),
'token' => $this->config->get('token'),
'dialog' => json_encode($dialog->toArray())
'dialog' => json_encode($dialog->toArray()),
];

return $bot->sendPayload($payload);
Expand Down Expand Up @@ -430,13 +430,14 @@ private function getBotId()
*/
public function extendConversation()
{
Conversation::macro('sendDialog', function(Dialog $dialog, $next, $additionalParameters = []) {
Conversation::macro('sendDialog', function (Dialog $dialog, $next, $additionalParameters = []) {
$response = $this->bot->replyDialog($dialog, $additionalParameters);

$validation = function($answer) use ($dialog, $next, $additionalParameters) {
$validation = function ($answer) use ($dialog, $next, $additionalParameters) {
$errors = $dialog->errors(Collection::make($answer->getValue()));
if (count($errors)) {
$this->bot->touchCurrentConversation();

return Response::create(json_encode(['errors' => $errors]), 200, ['ContentType' => 'application/json'])->send();
} else {
if ($next instanceof \Closure) {
Expand All @@ -446,6 +447,7 @@ public function extendConversation()
}
};
$this->bot->storeConversation($this, $validation, $dialog, $additionalParameters);

return $response;
});
}
Expand Down

0 comments on commit 42df8a6

Please sign in to comment.