Telegram Bot API
🌐 Tiếng Việt

setChatPhoto

Danh mục: Chat · Bot API 10.3 · Tài liệu chính thức

Đặt ảnh chat.

Giá trị trả về: Nếu thành công, trả về True.

Tham số

Tham sốKiểuBắt buộcMô tả
chat_idInteger or StringCóID chat
photoInputFileCóURL hoặc file_id của ảnh chat mới

Mô tả tham số chỉ là bản tóm tắt ngắn gọn; xem tài liệu chính thức để đọc toàn văn.

Ví dụ request

curl

curl -s "https://api.telegram.org/bot$TOKEN/setChatPhoto" \
  -F chat_id=123456789 \
  -F photo=@photo.jpg

Python

import requests

TOKEN = "123456789:AAEexampleTokenReplaceWithYours"
resp = requests.post(
    f"https://api.telegram.org/bot{TOKEN}/setChatPhoto",
    data={
        "chat_id": 123456789
    },
    files={"photo": open("photo.jpg", "rb")},
    timeout=30,
)
print(resp.json())

JavaScript

import { readFile } from "node:fs/promises";

const TOKEN = "123456789:AAEexampleTokenReplaceWithYours";
const form = new FormData();
form.append("chat_id", "123456789");
form.append("photo", new Blob([await readFile("photo.jpg")]), "photo.jpg");
const res = await fetch(`https://api.telegram.org/bot${TOKEN}/setChatPhoto`, { method: "POST", body: form });
console.log(await res.json());

Hướng dẫn từng bước: Cách tạo bot Telegram từ A đến Z: BotFather, token và tin nhắn đầu tiên