Baccarat 1 Telegram bot: the complete code
How to post every Pragmatic Play Baccarat 1 hand to a Telegram group: create the bot, hook it to the API stream and never repeat or miss a hand.
Published on November 2, 2026 · 8 min read
A Baccarat 1 Telegram bot posts every hand from the Pragmatic Play table to your group a few seconds after the dealer turns the last card, and it takes about 80 lines of Python on top of the /stream endpoint of LynxMetrics' Baccarat 1 API. This guide has the whole program, with no framework and a single dependency, and explains the four things that separate a bot that runs for months from one that dies on the first network hiccup.
Each round becomes a message like this:
♠ Baccarat 1 · 14:10:58 Player 7♠ 2♦ → 9 Banker A♣ 9♥ → 0 Winner: PLAYER (natural) Last 20: P B B P T P B P P B
The three ingredients
| What | Where you get it | What it costs |
|---|---|---|
| A Telegram bot | @BotFather, with the /newbot command | Free |
| The group id | https://api.telegram.org/bot<TOKEN>/getUpdates after posting in the group | Free |
| A Baccarat 1 key | The LynxMetrics dashboard, on the 2-hour trial or a subscription | Free trial, or R$ 21.90 per month on Pro |
A group id is negative, something like -1001234567890: if your number came out positive, you picked up the id of your private chat with the bot, not the group's. To only post messages, the bot does not need to be a group admin.
The Baccarat 1 trial lasts 2 hours with Pro plan limits, asks for no card and can be repeated every 24 hours. Since a Baccarat 1 round takes about 30 seconds, two hours of trial are around 240 hands: plenty of time to finish the bot, watch the messages land in the group and only then decide whether to subscribe.
Why does the bot use /stream instead of /latest?
Because /stream delivers the hand the moment it is stored, without the bot asking. The difference is large on two fronts: on speed, because there is no wait until the next poll, and on consumption, because holding the connection open costs 1 request against your per-minute limit, while polling /latest every 3 seconds costs 20. On the Pro plan the limit is 60 requests per minute, so /stream leaves the rest of it free for whatever else you want to do. The full comparison is in Baccarat 1 live results.
The whole bot
One dependency and three environment variables:
pip install httpx export LYNX_KEY="sk-lynx..." export TG_TOKEN="123456:ABC..." export TG_CHAT="-1001234567890"
bot.py
import json
import os
import time
from collections import deque
import httpx
LYNX_KEY = os.environ["LYNX_KEY"]
TG_TOKEN = os.environ["TG_TOKEN"]
TG_CHAT = os.environ["TG_CHAT"]
BASE = "https://api.lynxmetrics.com/v1/baccarat-1"
TELEGRAM = "https://api.telegram.org/bot" + TG_TOKEN + "/sendMessage"
RANKS = {"A": "A", "T": "10", "J": "J", "Q": "Q", "K": "K"}
SUITS = {"C": "♣", "D": "♦", "H": "♥", "S": "♠"}
MARK = {"player": "P", "banker": "B", "tie": "T"}
NAME = {"player": "PLAYER", "banker": "BANKER", "tie": "TIE"}
recent = deque(maxlen=20) # short strip for the message footer
posted = set() # ids already posted: the lock against duplicates
last_id = None # id of the last hand that went to the group
def hand(cards):
return " ".join(RANKS.get(c[0], c[0]) + SUITS[c[1]] for c in cards)
def message(round_):
data = round_["data"]
clock = round_["settledAt"][11:19]
marks = []
if data["natural"]:
marks.append("natural")
if data["player"]["pair"]:
marks.append("Player pair")
if data["banker"]["pair"]:
marks.append("Banker pair")
extra = " (" + ", ".join(marks) + ")" if marks else ""
return "\n".join([
"♠ <b>Baccarat 1</b> · " + clock + " UTC",
"Player " + hand(data["player"]["cards"]) + " → <b>" + str(data["player"]["score"]) + "</b>",
"Banker " + hand(data["banker"]["cards"]) + " → <b>" + str(data["banker"]["score"]) + "</b>",
"Winner: <b>" + NAME[round_["outcome"]] + "</b>" + extra,
"Last " + str(len(recent)) + ": " + " ".join(recent),
])
def post(round_):
global last_id
if round_["id"] in posted:
return
posted.add(round_["id"])
last_id = round_["id"]
recent.append(MARK[round_["outcome"]])
httpx.post(
TELEGRAM,
json={"chat_id": TG_CHAT, "text": message(round_), "parse_mode": "HTML"},
timeout=15,
)
def catch_up_from_results(since):
"""Long absence: the stream gave up resyncing, so page through what was missed."""
while True:
body = httpx.get(
BASE + "/results",
headers={"x-api-key": LYNX_KEY},
params={"after": since, "limit": 250},
timeout=30,
).json()
for round_ in body["data"]:
post(round_)
since = round_["id"]
if not body["nextCursor"]:
return
def follow():
headers = {"x-api-key": LYNX_KEY, "accept": "text/event-stream"}
if last_id:
headers["last-event-id"] = last_id
with httpx.stream("GET", BASE + "/stream", headers=headers, timeout=None) as response:
response.raise_for_status()
event = None
for line in response.iter_lines():
if line.startswith("event:"):
event = line.split(":", 1)[1].strip()
elif line.startswith("data:"):
body = json.loads(line.split(":", 1)[1])
if event == "ready":
if body.get("resyncError") == "too_many_missed":
catch_up_from_results(last_id)
for round_ in body.get("missed") or []:
post(round_)
if body["data"]:
post(body["data"])
elif event == "round":
post(body["data"])
elif event == "closed":
return "closed"
while True:
try:
if follow() == "closed":
print("another connection took over this key: exiting", flush=True)
break
except Exception as error:
print("dropped:", type(error).__name__, error, flush=True)
time.sleep(3)Run python bot.py, and on the next hand the group gets its first message.
The four things that make the bot last
Never repeat a hand
Every Baccarat 1 round id is fixed and never changes, which is why it works as a lock. The posted set covers two cases at once. The first is event: ready: when the connection opens, the API deliberately sends the last known round so your program has a starting point. The second is reconnecting after a drop, which repeats that same ready. Without the lock, every restart reposts the previous hand to the group — the most common mistake in a first bot.
Cover the gap without losing a hand
When reopening the connection, the bot sends the id of the last posted hand in the last-event-id header. The API then returns, inside ready, a missed list with the hands that closed while the bot was away, oldest first, up to 50 rounds. That is what makes a three-minute network drop pass unnoticed by the group.
Past 50 missed hands — about half an hour of table — the stream does not try to resync: it sends resyncError: "too_many_missed", and the catch_up_from_results function finishes the job through /results?after=, the same parameter explained in Baccarat 1 history. Note the order in the code: the catch-up runs before handling ready's data, so messages reach the group in the order the hands actually happened.
Treat reconnecting as routine, not as failure
Every /stream connection is closed after 6 hours, even a perfectly healthy one. A bot running all day reconnects about four times a day, so the while True at the bottom is not a patch over a bug: it is the expected behaviour. With last-event-id, none of those reconnections costs a hand.
event: closed is a different story. It means another connection opened with the same key and took the slot — on Pro a key holds 1 stream, on Business, 5. Reconnecting there would make the two copies evict each other forever, so the bot leaves the loop and logs why. Almost always it is a second copy of your own bot left running.
Do not hit Telegram's limit
Telegram accepts roughly 20 messages per minute in one group. A hand every 30 seconds is 2 per minute, so you have room — until you start posting streak alerts, hourly summaries and pair notices in the same group. If the total goes over, Telegram answers 429 with a retry_after, and honouring it is the right move. Our own API error codes follow the same logic and are listed in API errors and limits.
Message ideas, using fields that already arrive
- Pair and natural. The
data.player.pair,data.banker.pairanddata.naturalfields come with the round, and pair side bets are the most watched in baccarat. - Streak. When
currentStreak.lengthfrom/statsgoes past 4, add a line. That is at most one request per hand, which fits comfortably in Pro's 60 per minute. - Hourly summary. A
/stats?sample=100once an hour, with the percentages and the sample size next to them, for the reason explained in Baccarat 1 statistics. - Text Bead Road. The
recentstrip is already assembled; as coloured squares it looks like the table's own chart. - Hand in progress. With
?phases=1,event: phasearrives before the cards carrying theroundIdthe hand will have: you can post "hand in progress" and then edit that same message with the result througheditMessageText. Keep themessage_idbyroundId, and know how to drop a phase that never became a hand.
What if I want both baccarat tables in the same group?
Change the game name in the URL and use that API's key. Evolution's Lightning Baccarat answers in the same format with the same four endpoints, so BASE in the code becomes a variable and the bot runs two streams, one per table. The comparison is in Baccarat 1 vs Lightning Baccarat, and the other table's bot in Lightning Baccarat Telegram bot.
Where to run it, and the two security rules
The bot is light: its job is to hold one connection open and post two messages a minute, so any small VPS, container or always-on machine will do. What it cannot do is live in a serverless function with a short timeout, because /stream needs a process standing; in that case, poll /latest on a cron, store the id of the last handled hand and post only when it changes. The options are in where to host a bot.
The two rules worth more than the code: the API key and the Telegram token never go into the repository or to the browser side, and every bot deserves its own LynxMetrics project with its own key, so you can revoke one without taking the others down. More in API security.
Frequently asked questions
- Do I need to know how to program to build a Baccarat 1 Telegram bot?
You need basic Python, or another language with an HTTP client. The complete code in this article is about 80 lines and uses a single library, httpx, plus your Telegram bot token and a Baccarat 1 API key.
- How does the bot avoid posting the same hand twice?
By keeping the id of every round it has already posted. The id is fixed and never changes, and the stream's ready event deliberately repeats the last round when the connection opens, so without that lock every restart would repost the previous hand.
- What happens when the bot's connection drops?
It reopens the stream sending the id of the last posted hand in the last-event-id header, and the API returns in ready the hands that closed while it was away, up to 50. Beyond that it sends resyncError too_many_missed, and the bot finishes catching up through /results?after=. Every connection is also closed every 6 hours by design, so reconnecting is routine.
- Can I build and test the bot for free?
Yes. The Baccarat 1 API trial lasts 2 hours with Pro plan limits, no card, and can be repeated every 24 hours. Since a round takes about 30 seconds, two hours yield around 240 hands, enough to watch the bot posting before subscribing.
- Can I post Baccarat 1 and Lightning Baccarat in the same group?
Yes, because both APIs share the same format and endpoints: swap the game name in the URL and use that API's key. Each API is a separate subscription, with its own per-minute limit and its own stream connections.
For adults 18 and over only. LynxMetrics is not affiliated with Pragmatic Play or with the casinos that offer Baccarat 1, and it only sells data and stats, never predictions or betting tips, because every round is random and past results do not predict the next one.
Read also
- Baccarat 1 API (Pragmatic Play): live results in JSON
How LynxMetrics' Baccarat 1 API works: every hand from Pragmatic Play's table in JSON, the four endpoints, Python and Node examples, pricing and a free trial.
- Baccarat 1 vs Lightning Baccarat: which API to choose
The two tables side by side: Pragmatic Play's Baccarat 1 and Evolution's Lightning Baccarat, what changes in the game and what stays identical in the JSON.
- Pragmatic Play baccarat API: what exists and what does not
Searching for a Pragmatic Play API lands you in two worlds: the integration for licensed operators and a results API. What each is, and what LynxMetrics delivers.