Skip to content

Commit c97c1be

Browse files
committed
Merge branch 'sschlein-master'
2 parents cf20a13 + 3775bf8 commit c97c1be

File tree

6 files changed

+255
-0
lines changed

6 files changed

+255
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace BotMan\Studio\Console\Commands;
4+
5+
use Illuminate\Console\GeneratorCommand;
6+
use Symfony\Component\Console\Input\InputOption;
7+
8+
class BotManMakeConversation extends GeneratorCommand
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'botman:make:conversation {name} {--example}';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Create a new conversation class.';
23+
24+
/**
25+
* The type of class being generated.
26+
*
27+
* @var string
28+
*/
29+
protected $type = 'Conversation';
30+
31+
/**
32+
* Get the stub file for the generator.
33+
*
34+
* @return string
35+
*/
36+
protected function getStub()
37+
{
38+
if ($this->option('example')) {
39+
return __DIR__.'/stubs/conversation.example.stub';
40+
}
41+
42+
return __DIR__.'/stubs/conversation.plain.stub';
43+
}
44+
45+
/**
46+
* Get the default namespace for the class.
47+
*
48+
* @param string $rootNamespace
49+
* @return string
50+
*/
51+
protected function getDefaultNamespace($rootNamespace)
52+
{
53+
return $rootNamespace.'\Http\Conversations';
54+
}
55+
56+
/**
57+
* Get the console command options.
58+
*
59+
* @return array
60+
*/
61+
protected function getOptions()
62+
{
63+
return [
64+
['example', 'e', InputOption::VALUE_OPTIONAL, 'Generate a conversation with an example.'],
65+
];
66+
}
67+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace BotMan\Studio\Console\Commands;
4+
5+
use Illuminate\Console\GeneratorCommand;
6+
7+
class BotManMakeMiddleware extends GeneratorCommand
8+
{
9+
/**
10+
* The name and signature of the console command.
11+
*
12+
* @var string
13+
*/
14+
protected $signature = 'botman:make:middleware {name}';
15+
16+
/**
17+
* The console command description.
18+
*
19+
* @var string
20+
*/
21+
protected $description = 'Create a new middleware class.';
22+
23+
/**
24+
* The type of class being generated.
25+
*
26+
* @var string
27+
*/
28+
protected $type = 'Middleware';
29+
30+
/**
31+
* Get the stub file for the generator.
32+
*
33+
* @return string
34+
*/
35+
protected function getStub()
36+
{
37+
return __DIR__.'/stubs/middleware.stub';
38+
}
39+
40+
/**
41+
* Get the default namespace for the class.
42+
*
43+
* @param string $rootNamespace
44+
* @return string
45+
*/
46+
protected function getDefaultNamespace($rootNamespace)
47+
{
48+
return $rootNamespace.'\Http\Middleware';
49+
}
50+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace DummyNamespace;
4+
5+
use BotMan\BotMan\Messages\Incoming\Answer;
6+
use BotMan\BotMan\Messages\Conversations\Conversation;
7+
8+
class DummyClass extends Conversation
9+
{
10+
protected $name;
11+
12+
/**
13+
* @return mixed
14+
*/
15+
public function askForName()
16+
{
17+
$this->ask('What is your name?', function(Answer $answer) {
18+
19+
$this->name = $answer->getText();
20+
21+
$this->say('Nice to meet you '.$this->name);
22+
});
23+
}
24+
25+
/**
26+
* Start the conversation.
27+
*
28+
* @return mixed
29+
*/
30+
public function run()
31+
{
32+
$this->askForName();
33+
}
34+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace DummyNamespace;
4+
5+
use BotMan\BotMan\Messages\Conversations\Conversation;
6+
7+
class DummyClass extends Conversation
8+
{
9+
/**
10+
* Start the conversation.
11+
*
12+
* @return mixed
13+
*/
14+
public function run()
15+
{
16+
//
17+
}
18+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace DummyNamespace;
4+
5+
use BotMan\BotMan\BotMan;
6+
use BotMan\BotMan\Interfaces\Middleware\Heard;
7+
use BotMan\BotMan\Interfaces\Middleware\Sending;
8+
use BotMan\BotMan\Interfaces\Middleware\Captured;
9+
use BotMan\BotMan\Interfaces\Middleware\Matching;
10+
use BotMan\BotMan\Interfaces\Middleware\Received;
11+
use BotMan\BotMan\Messages\Incoming\IncomingMessage;
12+
13+
class DummyClass implements Received, Captured, Matching, Heard, Sending
14+
{
15+
/**
16+
* Handle a captured message.
17+
*
18+
* @param \BotMan\BotMan\Messages\Incoming\IncomingMessage $message
19+
* @param BotMan $bot
20+
* @param $next
21+
*
22+
* @return mixed
23+
*/
24+
public function captured(IncomingMessage $message, $next, BotMan $bot)
25+
{
26+
return $next($message);
27+
}
28+
29+
/**
30+
* Handle an incoming message.
31+
*
32+
* @param IncomingMessage $message
33+
* @param BotMan $bot
34+
* @param $next
35+
*
36+
* @return mixed
37+
*/
38+
public function received(IncomingMessage $message, $next, BotMan $bot)
39+
{
40+
return $next($message);
41+
}
42+
43+
/**
44+
* @param \BotMan\BotMan\Messages\Incoming\IncomingMessage $message
45+
* @param string $pattern
46+
* @param bool $regexMatched Indicator if the regular expression was matched too
47+
* @return bool
48+
*/
49+
public function matching(IncomingMessage $message, $pattern, $regexMatched)
50+
{
51+
return true;
52+
}
53+
54+
/**
55+
* Handle a message that was successfully heard, but not processed yet.
56+
*
57+
* @param \BotMan\BotMan\Messages\Incoming\IncomingMessage $message
58+
* @param BotMan $bot
59+
* @param $next
60+
*
61+
* @return mixed
62+
*/
63+
public function heard(IncomingMessage $message, $next, BotMan $bot)
64+
{
65+
return $next($message);
66+
}
67+
68+
/**
69+
* Handle an outgoing message payload before/after it
70+
* hits the message service.
71+
*
72+
* @param mixed $payload
73+
* @param BotMan $bot
74+
* @param $next
75+
*
76+
* @return mixed
77+
*/
78+
public function sending($payload, $next, BotMan $bot)
79+
{
80+
return $next($payload);
81+
}
82+
}

src/Providers/StudioServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use TheCodingMachine\Discovery\Discovery;
1010
use BotMan\Studio\Console\Commands\BotManListDrivers;
1111
use BotMan\Studio\Console\Commands\BotManInstallDriver;
12+
use BotMan\Studio\Console\Commands\BotManMakeMiddleware;
13+
use BotMan\Studio\Console\Commands\BotManMakeConversation;
1214

1315
class StudioServiceProvider extends ServiceProvider
1416
{
@@ -20,6 +22,8 @@ public function register()
2022
$this->commands([
2123
BotManListDrivers::class,
2224
BotManInstallDriver::class,
25+
BotManMakeMiddleware::class,
26+
BotManMakeConversation::class,
2327
]);
2428

2529
$this->discoverCommands();

0 commit comments

Comments
 (0)