Cycls supports asynchronous (async) applications, ideal for applications requiring high performance and scalability.

Creating an Async App

By following the steps below, you can create an asynchronous app with Cycls:

1

Import `AsyncApp`

Instead of importing App, you will import AsyncApp from Cycls.

main.py
from cycls import AsyncApp

app = AsyncApp(secret="sk-secret",
              handler="@handler-name")
2

Set Up the Entry Point

Define the entry point for your application, where the async responses will be handled.

main.py
@app
async def entry_point(context):
    # Capture the received message
    received_message = context.message.content.text
    # Send the response message
    await context.send.text(f"Received message: {received_message}")
3

Publish Your App

Publish your app by calling the publish method.

main.py
app.publish()
4

Run Your App

Run your app in the directory containing main.py:

python main.py

Complete Example

Here is the complete code for setting up an async app:

main.py
from cycls import AsyncApp

app = AsyncApp(secret="sk-secret",
              handler="@handler-name")

@app
async def entry_point(context):
    # Capture the received message
    received_message = context.message.content.text
    # Send the response message
    await context.send.text(f"Received message: {received_message}")

app.publish()