# Listening for External Requests

To handle and listen for requests that may come from any source via the Channel App Template, a basic HTTP server is required. Any popular development framework can be preferred to listen for requests coming through this server. In this document, FastAPI has been used as the development framework.

{% hint style="danger" %}
FastAPI has been used as the development framework, but it is not mandatory to use FastAPI.
{% endhint %}

Listening for a request using FastAPI is quite simple. First, add the [FastAPI](https://fastapi.tiangolo.com/) library to your project. Then, create a server as shown in the example below.

### Example Code

```py
from fastapi import FastAPI

app = FastAPI()

@app.post("/webhook")
async def handle_webhook(payload: dict):
    """
    Process the data sent by the webhook.
    """
    # Payload represents the data coming from the webhook here.
    # Perform your operations.
    return {"message": "Webhook received!"}
```

The example above listens for POST requests to the `/webhook` path and takes the incoming data as `payload`. Here, specified dictionary named `payload` is expected, but you can adjust this according to the incoming data.

### Notes

This example handles and processes incoming webhook data; however, in real projects, security, error handling, and other conditions should also be considered.

Before running this code, you need to install and run FastAPI. Additionally, this code requires Python version 3.6 or newer.

```
$ pip install fastapi
$ uvicorn main:app --reload
```

This example uses the `/webhook` path to listen for the webhook. Ensure that the data sent by the webhook matches the expected format.

{% hint style="danger" %}
In real projects, security measures, error handling, and other conditions should be taken into account.
{% endhint %}

By creating a FastAPI application in this way, you can listen for webhooks and perform operations based on the incoming data.

Additionally, after such development, the `Procfile` should be updated to indicate that FastAPI is being used as the development framework:

```
web: uvicorn channel_app_template.main:app --address=0.0.0.0 --port=8008
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.akinon.com/technical-guides/channel-app-template/development-steps/listening-for-external-requests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
