Coder Social home page Coder Social logo

botman's Introduction

BotMan

Latest Version on Packagist Build Status codecov Scrutinizer Code Quality Packagist StyleCI Slack Monthly Downloads

https://phppackagedevelopment.com

If you want to learn how to create reusable PHP packages yourself, take a look at my upcoming PHP Package Development video course.

About BotMan

BotMan is a framework agnostic PHP library that is designed to simplify the task of developing innovative bots for multiple messaging platforms, including Slack, Telegram, Microsoft Bot Framework, Nexmo, HipChat, Facebook Messenger and WeChat.

$botman->hears('I want cross-platform bots with PHP!', function (BotMan $bot) {
    $bot->reply('Look no further!');
});

If you want to learn how to create reusable PHP packages yourself, take a look at my upcoming PHP Package Development video course.

Documentation

You can find the BotMan documentation at https://botman.io.

Stand Alone Configuration

If you are installing Botman in a stand alone Laravel application, you can publish the configuration file with the following command:

php artisan vendor:publish --tag=config --provider="BotMan\BotMan\BotManServiceProvider"

Support the development

Do you like this project? Support it by donating

Contributing

Please see CONTRIBUTING for details.

0 1 2 3 4 5 6 7

Security Vulnerabilities

If you discover a security vulnerability within BotMan, please send an e-mail to Marcel Pociot at [email protected]. All security vulnerabilities will be promptly addressed.

License

BotMan is free software distributed under the terms of the MIT license.

botman's People

Contributors

antonkomarev avatar barryvdh avatar browner12 avatar carusogabriel avatar crynobone avatar feralheart avatar filippotoso avatar flavioheleno avatar holtkamp avatar iboldurev avatar juukie avatar karlisj avatar leedriscoll avatar lloople avatar luceos avatar luckyraul avatar m1guelpf avatar mosaxiv avatar mpociot avatar nfabre avatar ngfw avatar nyholm avatar philcross avatar ribb3r avatar sasha-x avatar sergix44 avatar slootjes avatar thedotedge avatar yuyaun avatar zaherg 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

botman's Issues

If a conversation answer contains a keyword that a hears() function is listening for, it will retrigger the conversation

I have a simple conversation that moves through a few questions for the user. Everything works well unless one of the answers contains the word 'this', if that happens, then the conversation goes back to the beginning.

Steps to replicate:

Take the following example

class PizzaConversation extends Conversation
{
    protected $size;

    public function askSize()
    {
        $this->ask('What pizza size do you want?', function(Answer $answer) {
            // Save size for next question
            $this->size = $answer->getText();

            $this->say('Got it. Your pizza will be '.$answer->getText());

            $this->askForToppings();
        });
    }

    public function askForToppings()
    {
        $this->ask('What toppings would you like?', function(Answer $answer) {

            $this->say('Got it. Your pizza will have ' . $answer->getText() . ' on it');

        });
    }

    public function run()
    {
        // This will be called immediately
        $this->askSize();
    }
}

If the answers are 'large' and then 'cheese and pineapple' then everything works as expected.

However, if the first answer was something like 'make this large' then the conversation will trigger the second question and loop back to the beginning asking the first question again.

If the conversation has 4 or 5 questions, at any point if the answer contains the word 'this' it always cycles back to the first question again.

Middleware Wit

When I use the Wit middleware, and I open the page in a browser, an error is thrown.
It works in the bot.

I fixed it with:

	if(!empty($entities))
	{

On line number 71 in BotMan/Middleware/Wit.php

State Methods

Hi,

Is there any methods to store data per bot conversation?

Lets say I want to store some data when the bot hears something and retrieve that info on a later stage, something like:

$bot->setProperty('foo', 'bar');
... 
// somewhere in another class or file
...
$bar = $bot->getProperty('foo'); //returns bar

Thank you.

fallback reply

Hi,

if I'm defining a Question object and set a fallback like ->fallback('Unable to create a new database') do I have to call something during $this->ask(... to "fire" the fallback? I'm using the example askForDatabase() from the docs and the fallback reply is not visible (facebook driver)

Thank you.

Skype support

Hello,

it's not quite clear from the description of this lib - whether the Skype group chats are supported by this lib? Could you please clarify?

Composer installation

Is there an issue with composer package?

I am trying to do composer require mpociot/slackbot and I get an error:

 [InvalidArgumentException]                                                   
  Could not find package mpociot/slackbot at any version for your minimum-sta  
  bility (stable). Check the package spelling or your minimum-stability  

Botman say additional parameters

Hi mpociot,
I can use below example, but i can not custom parameters via additionalparameters.

	// Add to cart
	public function insert_cart(BotMan $bot, $channel, $audiences_cart) {
		$bot->say('', $channel, FacebookDriver::DRIVER_NAME, [
			'message' => [
				'attachment' => [
					'type' => 'template',
					'payload' => [
						'template_type' => 'button',
						'text' => 'Please Click',
						'buttons' => [[
							'type' => 'postback',
							'payload' => 'PAYLOAD',
							'title' => 'Click Me',
						]],
					],
				],
			],
		]);
	}

Can i modify say() method of BotMan.php?

	/**
	 * @param string|Question $message
	 * @param string|array $channel
	 * @param DriverInterface|null $driver
	 * @param array $additionalParameters
	 * @return $this
	 */
	public function say($message, $channel, $driver = null, $additionalParameters = []) {
		if (is_null($driver)) {
			$drivers = DriverManager::getConfiguredDrivers($this->config);
		} else {
			$drivers = [DriverManager::loadFromName($driver, $this->config)];
		}

		foreach ($drivers as $driver) {
			$matchMessage = new Message('', '', $channel);
			/* @var $driver DriverInterface */
			$driver->reply($message, $matchMessage, $additionalParameters);
		}

		return $this;
	}

My commit record Link below:
(yuyaun@0db4130)

Slack's interactive messages without conversation

Hi,

I would like to use buttons-based actions but without having to build conversations e.g:

  • user says something
  • bot hears it and using replyfunction, returns some data + buttons
  • user clicks one of the buttons which will then do something

I might have missed something but I can't see how to do the above by just using the replyfunction as it doesn't have any callback to execute isInteractiveMessageReply like Answer object has.

Thanks
M

[Facebook] Add support for X-HUB-SIGNATURE header

Hi,

Facebook provides a X-HUB-SIGNATURE header to verify if the request to the bot endpoint is performed from facebook. This check is straightforward.

  1. Add config parameter to $config with the facebook app secret.
  2. Check every incoming request if $headers['X_HUB_SIGNATURE'] == 'sha1=' . hash_hmac('sha1', [REQUEST BODY], [APP SECRET])

Thanks.

Problems with facebook

Hi there, i have a small problem with this.

The bot only works for one request i mean, with one person. more people try but they don't have any answer...

Fallback always reply when conversing

I'm getting some trouble with your lib and slack.

Using this code :

    if (BotMan::isBot()) {
        return null;
    }

    BotMan::hears('hello', function ($bot) {
        $bot->reply('Hello answer ?');
    });

    BotMan::hears('deploy', function ($bot) {
        $bot->startConversation(new \App\DeployConversation());
    });

    BotMan::hears('totem', function ($bot) {
        $bot->startConversation(new \App\TotemConversation());
    });

    BotMan::fallback(function ($bot) {
        return $bot->reply('Fallback answer');
    });

    BotMan::listen();

When trying "hello", the only answer I get is "Hello answer" and nothing else : OK.
When trying "deploy", I got the first question (OK) AND the fallback message.
I followed the example you provide in the doc.

I you have any idea.

Thx for your answer and your lib.

[Telegram] Inline bot

I read all tests and manuals, but not found any info about it. Is there any opportunity to read inline queries to bot (in Telegram) and anwer on them?

Additional parameters on ask method

Hello.

I try to send a direct message with a question when bot is called from a channel, but ask method in ConversationClass doesn't have additional parameters. It's possible to add or I mustn't do that ?

Thanks

Default Service URLs should be in secure protocol (HTTPS)

For example, in BotFrameworkDriver.php line 165

$apiURL = Collection::make($matchingMessage->getPayload())->get('serviceUrl', 'http://skype.botframework.com');

It should be:

$apiURL = Collection::make($matchingMessage->getPayload())->get('serviceUrl', 'https://skype.botframework.com');

When,

$botMan = app('botman');
$botMan->say($message, $channel, 'BotFramework');

Throws an error

Object Moved

This document may be found here with 301 since API redirect to secure protocol.

No answer for a Conversation

Hi,

First, thank you for this great package.

I have this conversation class:

<?php
namespace App\Conversations;

use Mpociot\BotMan\Answer;
use Mpociot\BotMan\Conversation;
use Mpociot\BotMan\Question;

class IntroductionConversation extends Conversation
{
    protected $name;

    protected $email;

    protected $phone;

    public function askName()
    {
        $question = Question::create('Can I get your name please?')
            ->fallback('Unable to ask question')
            ->callbackId('ask_name');

        return $this->ask($question, function (Answer $answer) {
            $this->name = $answer->getText();
            $this->say('Nice to talk to you ' . $answer->getText());
        });
    }

    public function askEmail()
    {
        $question = Question::create('Can I get your email address please? You can say No if you wish to get phone calls notifications.')
            ->fallback('Unable to ask question')
            ->callbackId('ask_email');

        return $this->ask($question, function (Answer $answer) {
            if (str_contains($answer->getText(), ['nah', 'no', 'nope'])) {
                $this->say('That\'s fine, I\'ll ask you later if I need it');
            }
            $this->email = $answer->getText();
            $this->say('Don\'t worry. I\'ll never spam you!');
        });
    }

    public function askPhone()
    {
        $question = Question::create('Can I get your phone number please? You can say No if you don\'t wish to receive emails from me.')
            ->fallback('Unable to ask question')
            ->callbackId('ask_phone');

        return $this->ask($question, function (Answer $answer) {
            if (str_contains($answer->getText(), ['nah', 'no', 'nope'])) {
                $this->say('That\'s fine, I\'ll ask you later if I need it.');
            }
            $this->phone = $answer->getText();
            $this->say('Don\'t worry. I\'ll not wake you up on the middle of the night ;)');
        });
    }

    /**
     * Start the conversation
     */
    public function run()
    {
        $this->askName();
        $this->askEmail();
        $this->askPhone();
    }
}

When I initiate this conversation with $bot->startConversation(new IntroductionConversation); (in my case I am using Facebook messenger) all I get is the 3 questions directly.
screen shot 2016-12-13 at 16 43 02

On the run method, if I only keep the askName and remove the other two, I get the question, but when I answer it on messenger nothing happen.

Can any one help please...

Call to a member function reply() on string - Error

$bot->say('You have to verify your identity, please use this link: ' . $link, $bot->getMessage()->getUser(), BotFrameworkDriver::class);

Since BotMan.php Line 237

public function say($message, $channel, $driver = null)
    {
        $driver = new BotFrameworkDriver();
        if (is_null($driver)) {
            $drivers = DriverManager::getConfiguredDrivers($this->config);
        } else {
            $drivers = [$driver];
        }

        foreach ($drivers as $driver) {
            $matchMessage = new Message('', '', $channel);
            /* @var $driver DriverInterface */
            $driver->reply($message, $matchMessage, []);
        }

        return $this;
    }
$driver->reply($message, $matchMessage, []);

Above $driver instance is String since we send it as String from say() method and calling reply() method is throw the error.

Default response?

Hi, loving this library, I'll hopefully be contributing a little when I find something I can help with.

Quick question, how does one make the bot respond when nothing is matched by a $slackbot->hears()?

Thanks for taking the time to build this.

Use complex regular expression

It would be great to use complex regular expressions.

I have this code.

$botman->hears('deploy\s+([a-zA-Z]*)(?:\s*to\s*)?([a-zA-Z]*)?', function(BotMan $bot, $project, $env) {
});

I got the following error.

array_combine(): Both parameters should have an equal number of elements

i changed this line https://github.com/mpociot/botman/blob/master/src/Mpociot/BotMan/BotMan.php#L193 to

$parameters = array_slice($matches, 1);

works well, the variables are passed as expected.

Thank you.

Add Laravel example to readme.md

When I get a chance I'll update the readme.md with a working implementation on how to get SlackBot up and running from a Laravel 5 app.

Getting Started Issue - Argument 1 passed to Mpociot\SlackBot\SlackBot::__construct()

Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 1 passed to Mpociot\SlackBot\SlackBot::__construct() must be an instance of SuperClosure\Serializer

Hey I've copied and pasted your starter code and I get the following area above when using:

 $slackBot = new SlackBot();
        $slackBot->initialize(env('SLACK_TOKEN'));

The documentation isn't very clear to me about how to interact with the bot from your tutorial or github page, I did get the url verified in Slack but when I write to the bot "hello" I get no response back due to the error above.

Nothing being passed in Payload

For some reason, the payload that comes from Slack is empty, is that an issue with the repo, or slack?

I followed your directions, setup a route that responds with the URL verification, that works just fine, but when I send a message to the bot, Slack sends a message with the $request variable being completely empty. Am I missing something here?

[1.1] Add "say" method to send messages to users

Right now it's only possible for BotMan to react to incoming messages (through webhooks).
But some applications will need the ability to originate messages to the user based on some internal logic.

BotMan needs to be extended with a say method.
This method accepts a channel.

Depending on the messaging driver the channel is:

  • A Slack User-ID
  • A Facebook User-ID
  • A Skype User-ID
  • A SMS recipient numebr
  • A Telegram User-ID

The idea would be that you can use the say method without the need to specify the driver. In this case, BotMan will try to deliver the message through all drivers that are configured.

The second option would be, to use a Driver class as an argument for the say method.

Example syntax:

No driver specified

$botman = BotManFactory::create($config);
$botman->say('Hello!', 'channel_id_123456789');

With additional messaging service parameters

$botman = BotManFactory::create($config);
$botman->say('Hello!', [
    'channel' => 'channel_id_123456789'
]);

With a predefined messaging driver

$botman = BotManFactory::create($config);
$botman->say('Hello!', 'channel_id_123456789', FacebookDriver::class);

Thoughts? Ideas? :)

Mattermost support

Mattermost is an open source, self-hosted Slack-alternative

As an alternative to proprietary SaaS messaging, Mattermost brings all your team communication into one place, making it searchable and accessible anywhere. It’s written in Golang and React and runs as a production-ready Linux binary under an MIT license with either MySQL or Postgres.

Mattermost is bundled with GitLab Omnibus and it would be great if we could suport it

Bot does not listen very well :D

I think this only happens with replies. I did not had this issue with conversations. I use Telegram as a provider.

screenshot from 2016-12-16 00-32-06
screenshot from 2016-12-16 00-30-57

With two methods in the controller...

screenshot from 2016-12-16 00-35-50
screenshot from 2016-12-16 00-37-39

Nothing wrong in logs

Second ask() answer in conversation can't be detected

Hello, I have some trouble with conversation. If I do one method only with one question - it works well, but if I want to ask one more question in another method from first - I have issue like on the picture.

Issue picture

The problems are:

  1. Another username and icon for ask() method
  2. Answer on ask() in askAnswer() don't catch, instead of it I see reply of $botman->fallback

The code is here:

public function run()
    {
        $this->askQuestion();
    }
    
    public function askQuestion() {
        $this->ask('Ok! I am ready to learn new phrases. On what message or pattern I should to have reaction?', function (Answer $answer) {    
            $this->question = strtolower($answer->getText());
            if ($this->question != null) {
                $this->say('Got it.', $this->parameters);
                $this->askAnswer();
            } else {
                $this->say('Sorry, something is wrong with your question, try to teach me again!', $this->parameters);
            } 
        });
    }

    public function askAnswer() {
        $this->ask('And what answer should to be on this?', function (Answer $answer) {
            $this->answer = strtolower($answer->getText());
            if ($this->answer != null) {
                $this->say('Understood!', $this->parameters);
                $this->remember($this->question, $this->answer);
            } else {
                $this->say('Sorry, something is wrong with the answer, try to teach me again!', $this->parameters);
            }
        });
    }

I've tried to do second ask in first method, but anyway I have the same problem.
It is slackRTM driver.
May be I do something wrong? Can you give any advice to me?

how to add a menu ?

I'm not sure if this is in the scope of this project. But I've noticed that a lot of Facebook Messenger bots are integrating a little menu that can be used to navigate to different options or conversations.

These are two bots that make use of the menu

Coding Memes: https://www.messenger.com/t/272687346480612
Alexa Dating: https://www.messenger.com/t/alexadating

I'm wondering how those menus are created, and whether Botman can help or plans to add this feature in the future.

Thanks!

Specify outbound driver

With SlackBot it was possible to use the reply outside of the standard hear etc to send a message. Is there a way to specify the driver to keep using this functionality?

ie. bot initiated message

Pubish on packagist

Hi,

Thanks for your work, this looks very interesting. Would you mind publishing your lib on packagist? Would make testing/improving/installing way easier.

Thanks,

Unnecessary "new Curl()" in Readme.

On Readme.md:97, there is a new Curl() being passed to the Botman class; the Botman Constructor does not know what to do with the extra argument. Is the Curl Handler something that is required in a future version, or is it something that is no longer necessary? Either way, the documentation should be updated to reflect the current version.

Callback after ask in Conversation not executed

Hi
When I try to ask a question with buttons in facebook the callback funktion for ask is not executed if I click on the button or reply with text.

$buttons = [];
foreach($trip->destination->points as $point){
   $buttons[] = Button::create($point->name)->value($point->name)->image('https://bvb.to/assets/images/square.png');
}
    
$question = Question::create('Ich habe die Zielhaltestelle nicht gefunden :( Welche meintest Du?')
->fallback('Ich gebe auf..')
->callbackId('Ziel')
->addButtons($buttons);

$this->ask($question, function (Answer $answer) {    // Is not triggered, $answer is empty 
    if ($answer->isInteractiveMessageReply()) {			        
        $this->ziel = $answer->getValue();
    } else {
        $this->ziel = $answer->getText();
    }
    $this->startConversation();
});

Button Callback_id Missing

It appears according to the Slack API you are now required to send a callback_id with buttons, can that be added relatively easily?

callback_id
string
The provided string will act as a unique identifier for the collection of buttons within the attachment. It will be sent back to your message button action URL with each invoked action. This field is required when the attachment contains message buttons. It is key to identifying the interaction you're working with.

[Laravel] Set configuration programmatically

Great library!
But, maybe I missed something. I see that the config for the botfactory is passed as a simply array with plain PHP, but with Laravel, it's hardcoded in the services.php.
I need to manage different tokens with different webhooks (simply, different bots that appears differently but work the same way with the same backend). it's possible to implement something like this with this library?

Blog post code formatting.

The project blog post could use source code color formatting to improve legibility.

There's probably some decent way to do it with Jekyll.

Telegram: Conversations

Hello,

I use botman in a new Laravel 5.3 application. I have tried with the laravel starter, but i couldnt get it to work. So i started with a clean install.

As I am not very familiar with Laravel, I got it working, except the conversations. I have taken the Example conversations from the Laravel Starter.

When I use Start Conversation, the conversation is triggered and the buttons appear in Telegram. When I click a button, nothing happens.

Can it be something with the cache? As i can read in previous issues and documentation, when used in Laravel, caching is automatic handled?

Controller

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Mpociot\BotMan\BotManFactory;
use Mpociot\BotMan\BotMan;
use App\Conversations\ExampleConversation;

class BotManController extends Controller
{
	public function handle(Request $request)
	{
		$botman = app('botman');

		// Simple respond method
		$botman->hears('Hello|hi|Hi', function (BotMan $bot) {
			//Reply
			$bot->reply('Hi there :)');
		});

		$botman->hears('Start conversation', function (BotMan $bot) {
			$bot->startConversation(new ExampleConversation());
		});
		
		$botman->listen();
	}
}

Conversation

namespace App\Conversations;

use Illuminate\Foundation\Inspiring;
use Mpociot\BotMan\Answer;
use Mpociot\BotMan\Button;
use Mpociot\BotMan\Conversation;
use Mpociot\BotMan\Question;

class ExampleConversation extends Conversation
{
    /**
     * First question
     */
    public function askReason()
    {
        $question = Question::create("Huh - you woke me up. What do you need?")
            ->fallback('Unable to ask question')
            ->callbackId('ask_reason')
            ->addButtons([
                Button::create('Tell a joke')->value('joke'),
                Button::create('Give me a fancy quote')->value('quote'),
            ]);
        return $this->ask($question, function (Answer $answer) {
            if ($answer->isInteractiveMessageReply()) {
                if ($answer->getValue() === 'joke') {
                    $joke = json_decode(file_get_contents('http://api.icndb.com/jokes/random'));
                    $this->say($joke->value->joke);
                } else {
                    $this->say(Inspiring::quote());
                }
            }
        });
    }

    /**
     * Start the conversation
     */
    public function run()
    {
        $this->askReason();
    }
}

Support the realtime bot API

Great library, I'm looking at using the Slack realtime bot API, whereas botman seems to be geared to the webhook type of integration in/out.

Is it possible to use this library in the same way as jclg/php-slack-bot for example?

It looks so, by running with slack_token in the config, but when running the Slack example, the $botman->listen() just exists and doesn't connect/listen - it's highly likely I may have missed something.

How to use slack slash commands?

https://api.slack.com/slash-commands#triggering_a_command

<?php
require_once "../vendor/autoload.php";

header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json; charset=utf8');


use Mpociot\BotMan\BotManFactory;
use Mpociot\BotMan\BotMan;
// create an instance
$config = [
    'slack_token' => '-hidden-'
];

$botman = BotManFactory::create($config);

$botman->hears("/srv", function (BotMan $bot)
{
    $bot->reply("Tell me more!");
});

$botman->fallback(function(BotMan $bot)
{
    $trigger = $bot->getMessage()->getPayload()['command'];
    $bot->reply("'".$trigger."' is an unknown command");
});
// start listening
$botman->listen();

Replies to /srv:
'/srv' is an unknown command

what am I missing?

Attachment builder for message object

Hi

The documentation makes reference to creating a message object when wanting to create 'pretty' messages.

Slack-specific fields and attachments:

Is it possible for you to include a function to the slackbot class that allows for attachments to be added to the bot->reply, with an attachment builder | attachment object as a parameter?

Otherwise, a message object parameter that can build attachments too.

Regards

Using $this->say / $botman->say doesn't use bot account

When sending a message using $this->say in conversations, or $botman-say in other contexts, it appears that the bot details aren't used.

333_1482365288 1

The code for this is:

public function askWhatTypeOfTraining()
    {
        return $this->ask("What type of training are you asking about? [Answer with *type_a* or *type_b*]",
            function (Answer $answer) {
                $this->typeOfTraining = strtolower($answer->getText());

                if ($this->typeOfTraining == "type_a") {
                    $this->say("This is how you complete type_a training.");
                } elseif ($this->typeOfTraining == "type_b") {
                    $this->say("This is how you complete type_b training.");
                }
            });
    }

    /**
     * Start the conversation.
     */
    public function run()
    {
        $this->askWhatTypeOfTraining();
    }

Not able to diagnose if this is a bug, or if it's down to my incompetence. Any ideas gratefully received!

Fallback is continuously sending same message

Perhaps I am using the fallback() function of the bot incorrectly to catch anything that doesn't match the phrases my bot is hearing for - however if I type something that I haven't defined it is being picked up by the fallback() function and then continuously spamming the same message in quick succession.

The below is what i have in my controller for messages from Slack.

$slackBot = app('slackbot');

        if (!$slackBot->isBot()) {
            
            $slackBot->hears('ping', function (SlackBot $bot) use ($request) {
                $bot->reply('Pong :table_tennis_paddle_and_ball:');
            });
            
            $slackBot->hears('hello', function (SlackBot $bot) use ($request) {
                $bot->reply('World! :earth_asia:');
            });
            
            $slackBot->hears('buttons', function (SlackBot $bot) use ($request) {
                $bot->reply(Question::create('Here are some buttons!')->addButton(Button::create('Hello World')->value('hello world'))->callbackId("helloWorldButton"));
            });
            
            $slackBot->hears('msg', function (SlackBot $bot) use ($request) {

              $bot->startConversation(new MessageConversation());
            
            });
            
             $slackBot->fallback(function(SlackBot $bot) {
                $bot->reply('Sorry? I don\'t understand.');
            });
            
            $slackBot->listen();
            
        } else {
            return null;
        }

It is this part here that continuously replies with the sorry message:

$slackBot->fallback(function(SlackBot $bot) {
                $bot->reply('Sorry? I don\'t understand.');
            });

Is this a bug, or am I doing something wrong?

(Optionally) Wrap Messages in a Message Object for additional payloads

I'd like to have the possibility to send images.

Keeping the current API, we could check if the message is a Message Object or the current string and handle them separately.

$message = Message::create([
    'text' => 'Have a look at this wonderful image',
    'image' => 'http://placepenguin.com/500/250'
]);

$message = Message::text('Have a look at this wonderful image')->image('http://placepenguin.com/500/250');

$botman->say($message);

I think it's also worth the idea to have an image parameter which holds the data of the image or just an URL where the image is located.

how to add middleware for api.ai?

Hi there,

In your docs you show how to add a middleware for Wit.ai

$botman->middleware(Wit::create('MY-WIT-ACCESS-TOKEN'));
$botman->hears('emotion', function($bot) {
    $extras = $bot->getMessage()->getExtras();
    // Access extra information
    $entities = $extras['entities'];
});

And indeed you include the Wit middleware in your package.

But what about for Api.ai ? Are we supposed to create our own middleware?

Also it would be really helpful if you could add a fully working basic example that makes use of these middlewares

Btw am loving your package! Got set up with a facebook bot in 20 minutes flat!

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.