Botman: Botman userStorage problem

Created on 13 Nov 2020  路  5Comments  路  Source: botman/botman

  • BotMan Version: 2
  • Laravel Version: 5.8.38
  • PHP Version: 7.2.23
  • Messaging Service(s): Facebook
  • Cache Driver: file

Description:

I have issue with userStorage.

I have two facebook account.
When I write from my first facebook account to messenger, the user selects a city from Generic Themplate. It writes this response to userStorage. But when I write from the second account and choose city, userStorage displays the answer from the first. How can I fix it.

Most helpful comment

@s4rrow where do you see that example of use

//...
 $miasto = $userStorage[0]->get('miasto');
//...

i think you dont need to insert data directly inside botman Storage
that looks like sample data collections inside Laravel

p.s. you need to read Read from storage

All 5 comments

@s4rrow can you post a code of your conversations?

Save to UserStorage - botman.php

$botman->hears('Bia艂ogard', function($bot)
               {
                   $miasto = 'bialogard';
                   $bot->userStorage()->save([
                       'miasto' => $miasto
                   ]);


                   $bot->startConversation(new UpdateBazyKlub());

                });

Add to database from user storage - UpdateBazyKlub

        $userStorage = $this->bot->userStorage()->all();
        $miasto = $userStorage[0]->get('miasto');
        User::Test($this->bot->getUser(), $miasto);

User::Test

    {


        User::updateOrCreate([
            'fb_id' => $user->getId()], [

            'klub' => $miasto,


        ]);
    }

And next step i show general menu.

 public function menu()

    {

    $userStorage = $this->bot->userStorage()->all();
    $miasto = $userStorage[0]->get('miasto');

i use $miasto variable to build link

$this->bot->reply(GenericTemplate::create()

                    ->addElements([
                        Element::create('Oferta')
                            ->subtitle('Sprawd藕 ofert臋 klub贸w Xtreme Fitness Gyms')
                            ->image('https://website.com/tlo1.jpg')


                        ->addButton(ElementButton::create('馃憠 Oferta')
                            ->url('https://www.website.pl/'.$miasto.'/price')) 

@s4rrow can you post a code of your conversations?

@s4rrow where do you see that example of use

//...
 $miasto = $userStorage[0]->get('miasto');
//...

i think you dont need to insert data directly inside botman Storage
that looks like sample data collections inside Laravel

p.s. you need to read Read from storage

@s4rrow where do you see that example of use

//...
 $miasto = $userStorage[0]->get('miasto');
//...

i think you dont need to insert data directly inside botman Storage
that looks like sample data collections inside Laravel

p.s. you need to read _Read from storage_

Thanks, my fault.

i change:

```
$userStorage = $this->bot->userStorage()->all();
$miasto = $userStorage[0]->get('miasto');


$userStorage = $this->bot->userStorage()->find();
$miasto = $userStorage ->get('miasto');
```

And works. I close topic!

Good For you!)

Was this page helpful?
0 / 5 - 0 ratings