question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Composing Handlers?

See original GitHub issue

Hello, Is Is possible to using multiple levels of handler? for exmpale:

bot.onEvent(mainHandler)
const mainHandler = new LineHandler()
    .onFollow(async context => {
        return true
    }, followHandler)
    .onUnfollow(async context => {
        return true
    }, unfollowHandler)
    .onEvent(middleware([
        termAndServiceAgreement,
        isLoggedIn,
        eventHandlers
    ]))
    .onError(async (context, err) => {
        await context.sendText(err)
    })
    .onUnhandled(doNothing)

const eventHandlers = new LineHandler()
    .onEvent(async context => {
        const answer = 'somthing';
        switch (answer) {
            case case1:
                context([]);
                break;
            case case2:
                const anotherHandler = handler1.build()
                anotherHandler(context)
                break;
            default:
                // code
                doNothing()
        }
    })

const handler1 = new LineHandler()
    .onEvent(async context => {
        // do something
    })

I see there bottender-compose, but it seems i can’t do something in the second parameter, only send actions.

bot.onEvent(
  condition([
    [context => false, sendText('a')],
    [context => false, sendText('b')],
    [context => true, sendText('c')],
  ])
);

what if i i wanna check something in context.state and call 3r party services or pass to another event handler??

Thanks~~~

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
tw0517twcommented, Nov 27, 2018

Hi @yusef-ho ,

You can try use DEBUG environment varaible to check incoming events, then you may find out what events are triggering what actions.

https://bottender.js.org/docs/Guides-Troubleshooting#i-want-to-know-if-therere-incoming-requests-to-my-bot

0reactions
tw0517twcommented, Nov 30, 2018

I’m going to close this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Side-effects in Compose - Android Developers
A side-effect is a change to the state of the app that happens outside the scope of a composable function. Due to composables'...
Read more >
Full Guide to Jetpack Compose Effect Handlers - YouTube
The new effect handlers in Jetpack Compose can be quite a pain to deal with if you don't fully understand their purpose.
Read more >
Rust's Iron Framework: Composing Handlers | by Eric Opines
I'm learning Iron and its ecosystem as I work through this application. It could be there are better ways of doing things using...
Read more >
Jetpack Compose Effect Handlers - by Jorge Castillo
Used for notifying state updates to objects not managed by Compose. For effects that do not require dispose. Runs after every successful ...
Read more >
Jetpack Compose Effect Handlers - ‍ Jorge Castillo
Jetpack Compose Effect Handlers. Learn how to run your side effects bound to the @Composable lifecycle. This post has been moved to the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found