Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Comments

Enable to give shared objects to dialogs from main logic#38

Merged
uezo merged 1 commit intomasterfrom
develop
Sep 4, 2020
Merged

Enable to give shared objects to dialogs from main logic#38
uezo merged 1 commit intomasterfrom
develop

Conversation

@uezo
Copy link
Owner

@uezo uezo commented Sep 4, 2020

Main logic:

# API Client shared with all dialogs
api = AwesomeAPI()

# create bot
bot = Minette()
# set shared object
bot.dialog_uses(apiclient=api)

Then, all DialogServices/DialogRouter can use api object as apiclient:

self.dependencies.apiclient.get_awesome_info()

If you want to share objects with specific dialog:

bot.dialog_uses(
    {
        FooDialog: {"onlyforfoo": onlyforfoo}
    }
    apiclient=api
)

Then, onlyforfoo is set only to FooDialog and apiclient is set to all.

Main logic:

```python
# API Client shared with all dialogs
api = AwesomeAPI()

# create bot
bot = Minette()
# set shared object
bot.dialog_uses(apiclient=api)
```

Then, all DialogServices/DialogRouter can use `api` object as `apiclient`:

```python
self.dependencies.apiclient.get_awesome_info()
```

If you want to share objects with specific dialog:

```python
bot.dialog_uses(
    {
        FooDialog: {"onlyforfoo": onlyforfoo}
    }
    apiclient=api
)
```

Then, `onlyforfoo` is set only to `FooDialog` and `apiclient` is set to all.
@uezo uezo merged commit fa5c4c4 into master Sep 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant