35274-vm/webhook_docs.php
Flatlogic Bot d2f005da56 nu norm
2025-10-27 13:55:31 +00:00

94 lines
4.9 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once 'db/config.php';
require_once 'layout_header.php';
?>
<div class="container mt-4">
<div class="card">
<div class="card-header">
<h1 class="card-title">Webhook Documentation</h1>
<p class="card-subtitle mb-2 text-muted">Everything you need to integrate with external services like n8n.</p>
</div>
<div class="card-body">
<p>Webhooks are a powerful way for your application to send and receive information from other services in real-time. Heres how they work in your CRM.</p>
<hr>
<h2 class="mt-4">Outgoing Webhooks</h2>
<p>Your application sends these webhooks when certain events happen. You can set the destination URL in the <a href="settings.php">Settings</a> page.</p>
<div class="card mt-3">
<div class="card-header bg-light">
<strong>Event: New Post Scheduled</strong>
</div>
<div class="card-body">
<p>This webhook is sent every time you schedule a new post in the <a href="scheduler.php">Scheduler</a>. It tells your external service (e.g., n8n) that a new post needs to be generated and published.</p>
<p><strong>Method:</strong> <code>POST</code></p>
<p><strong>Data Format:</strong> <code>application/json</code></p>
<h6>Example Payload:</h6>
<pre class="code-block-dark p-3 rounded"><code>{
"event": "new_post_scheduled",
"channel_identifier": "@my_telegram_channel",
"post_text_idea": "A post about morning coffee",
"scheduled_at_utc": "2025-10-28 14:30:00",
"post_id": 123
}</code></pre>
<h6>Field Descriptions:</h6>
<ul>
<li><code>event</code>: The name of the event (always "new_post_scheduled").</li>
<li><code>channel_identifier</code>: The public URL or @name of the target channel (e.g., "@my_channel" or "t.me/joinchat/...").</li>
<li><code>post_text_idea</code>: The initial text or idea you entered in the scheduler. Your n8n workflow should use this as a prompt for AI text generation.</li>
<li><code>scheduled_at_utc</code>: The planned publication time in UTC.</li>
<li><code>post_id</code>: The unique ID of the post in this CRM, which can be used for status updates.</li>
</ul>
</div>
</div>
<hr class="my-5">
<h2 class="mt-4">Incoming Webhooks</h2>
<p>Your application can also receive webhooks from other services. This is how your n8n workflow reports back on the result of a publication.</p>
<p>The unique and secure URL for incoming webhooks is available on the <a href="settings.php">Settings</a> page.</p>
<div class="alert alert-warning" role="alert">
<strong>Important:</strong> The payload for incoming webhooks is different from the outgoing ones. You must send a status update, not the original event data.
</div>
<div class="card mt-3">
<div class="card-header bg-light">
<strong>Purpose: Report Publication Status</strong>
</div>
<div class="card-body">
<p>After your n8n workflow attempts to publish a post, it **must** send a webhook back to your CRM to report the outcome. This allows the system to update the post's status from "pending" to "published" or "failed".</p>
<p><strong>Method:</strong> <code>POST</code></p>
<p><strong>Data Format:</strong> <code>application/json</code></p>
<h6 class="mt-4">Required Fields:</h6>
<ul>
<li><code>post_id</code> (integer): The ID of the post this update refers to. <strong>This is mandatory.</strong></li>
<li><code>status</code> (string): The outcome. Use <code>published</code> for success or <code>failed</code> for an error.</li>
</ul>
<h6 class="mt-4">Example Payload (Success):</h6>
<p>This is the minimal payload you need to send for a successful publication.</p>
<pre class="code-block-dark p-3 rounded"><code>{
"post_id": 123,
"status": "published"
}</code></pre>
<h6 class="mt-4">Example Payload (Error):</h6>
<p>If something goes wrong, send this payload. You can include an optional <code>details</code> field for error messages.</p>
<pre class="code-block-dark p-3 rounded"><code>{
"post_id": 123,
"status": "failed",
"details": "Telegram API error: Chat not found."
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<?php require_once 'layout_footer.php'; ?>