Skip to content

Bot API Overview

At its core, you can think of the SafeW Bot API as software that provides JSON-encoded responses to your queries.

A bot, on the other hand, is essentially a routine, software or script that queries the API by means of an HTTPS request and waits for a response. There are several types of requests you can make, as well as many different objects that you can use and receive as responses.

Obtain Your Bot Token

In this context, a token is a string that authenticates your bot (not your account) on the bot API. Each bot has a unique token which can also be revoked at any time via @BotFather.

Obtaining a token is as simple as contacting @BotFather, issuing the /newbot command and following the steps until you're given a new token. You can find a step-by-step guide here.

Your token will look something like this:

4839574812:AAFD39kkdpWt3ywyRZergyOLMaJhac60qc

Making Requests

All requests are authenticated via the token in the URL, using the following format:

https://api.safew.org/bot<YOUR_BOT_TOKEN>/methodName

Since your browser is capable of sending HTTPS requests, you can use it to quickly try out the API. After obtaining your token, try pasting this string into your browser:

https://api.safew.org/bot<YOUR_BOT_TOKEN>/getMe

In theory, you could interact with the API with basic requests like this, either via your browser or other tailor-made tools like cURL. While this can work for simple requests like the example above, it's not practical for larger applications and doesn't scale well.

Request data is formatted as JSON. File uploads use multipart/form-data.

Standard Response Format

Success Response

json
{
  "ok": true,
  "result": {
    ...
  }
}

Error Response

json
{
  "ok": false,
  "error_code": 400,
  "description": "Bad Request: ...",
  "trace_id": "abc123"
}

Common Error Codes

CodeDescription
400Bad request parameters
401Invalid or expired token
403Bot does not have permission to perform this action
404Method not found or resource does not exist
429Too many requests, rate limit triggered
500Internal server error

Available Methods

Basic Methods

MethodDescriptionHTTP Method
getMeGet basic Bot informationGET / POST
getUpdatesLong polling to get updatesGET / POST

Sending Messages

MethodDescriptionHTTP Method
sendMessageSend a text messagePOST
sendPhotoSend a photoPOST
sendVideoSend a videoPOST
sendVoiceSend a voice messagePOST
sendAudioSend an audio filePOST
sendDocumentSend a documentPOST
sendMediaGroupSend a media groupPOST

Editing Messages

MethodDescriptionHTTP Method
editMessageTextEdit message textPOST
editMessageReplyMarkupEdit message reply markupPOST

File Upload Notes

The following methods support file uploads and require multipart/form-data encoding:

  • sendPhoto - Photo file, max 10MB
  • sendVideo - Video file
  • sendVoice - Voice file
  • sendAudio - Audio file
  • sendDocument - Document file, max 100MB
  • sendMediaGroup - Media group, max 10 files

In addition to uploading files directly, you can also pass a file_id of a previously uploaded file to reuse it.