Skip to content

Conversation

heyitsaamir
Copy link
Collaborator

@heyitsaamir heyitsaamir commented Aug 8, 2025

This is a similar draft for being able to create augmentable activity context (See microsoft/teams.ts#288). Here is how it actually looks like in practice:

class Foo:
    bar: str


class FooPlugin(Plugin[Foo]):
    def on_activity(self):
        return Foo()


app = App(AppOptions(plugins=[FooPlugin()]))

@app.on_message
async def handle_message(ctx: ActivityContext[MessageActivity]):
   foo_ctx = ctx.get_plugin_context(FooPlugin)
   foo_ctx.bar # this is correctly str

What this means is that we can build plugins like a GraphPlugin which will then give us access to graph_ctx.user_graph, for example. And it gives plugins additonal flexibility to add custom things to the activity context as desired.

In typescript, the nice thing is that we can just do activityContext.bar, and it'll be correctly inferred. But python's type system is not nearly as powerful as typescript, so we have to explicitly ask ActivityContext the type for the plugin (hence foo_ctx = ctx.get_plugin_context(FooPlugin)) so we get the right types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant