This project implements a custom channel receiver for Front, a customer communication platform. It creates a webhook handler to process messages sent from Front and potentially relay them to another service or platform.
The main components of this project are:
- A webhook handler (
src/webhook-handler.ts
) that processes incoming messages from Front. - A type definition file (
src/types.ts
) that defines the structure of messages received from Front. - A main file (
src/index.ts
) that sets up and runs the server.
The webhook handler listens for POST requests on the /front/send-message
endpoint. When a message is received:
- It parses the incoming JSON payload as a
FrontMessage
type. - It logs the received message and some key details (sender and recipient contact handle).
- It's set up to potentially send this message to another service (currently just logs a placeholder message).
- It returns a success response if everything processes correctly, or an error response if something goes wrong.
- TypeScript
- Hono as the web framework
- tsx for running TypeScript directly
- env-cmd for managing environment variables in the dev environment
This project includes a middleware function that checks for a valid API key in the X-Front-Signature
header of incoming requests. Make sure to set the FRONT_WEBHOOK_SECRET
environment variable to the expected value.
-
Clone the repo, and set the
FRONT_WEBHOOK_SECRET
environment variable in a.env
file. -
Install dependencies:
pnpm install
-
Start the development server (runs on port 3000 by default):
pnpm run dev
-
Serve your app; tools like ngrok or localcan are useful for this.
-
Configure your custom channel in Front to point to your URL + path (e.g.
https://abc123.ngrok-free.app/front/send-message
). -
Test the integration by sending a message from Front via your custom channel.
To complete this integration:
- Implement the actual message sending logic in the webhook handler.
- Set up proper error handling and logging.
- Configure environment variables for any sensitive information or configuration.
- Set up proper testing for the webhook handler.
- Deploy the service to a production environment.