---
agentTools:
  projectIndex: https://telegram-bot-sdk.readme.io/llms.txt
---

# setWebhook

Use this method to specify a url and receive incoming updates via an outgoing webhook.

Use this method to specify a URL and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified URL, containing a JSON-serialized [Update](https://core.telegram.org/bots/api#update). In case of an unsuccessful request, we will give up after a reasonable amount of attempts.

If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. `https://www.example.com/{token}`. Since nobody else knows your bot‘s token, you can be pretty sure it’s us.

See [setWebhook](https://core.telegram.org/bots/api#setwebhook) official docs for a list of supported parameters and other info.

[block:callout]
{
  "type": "info",
  "body": "**1.** You will not be able to receive updates using [getUpdates](https://telegram-bot-sdk.readme.io/docs/getupdates) for as long as an outgoing webhook is set up.\n**2.** To use a self-signed certificate, you need to upload your [public key certificate](https://core.telegram.org/bots/self-signed) using the certificate parameter. Please upload as InputFile, sending a String will not work.\n**3.** Ports currently supported for Webhooks: **443**, **80**, **88**, **8443**.",
  "title": "Notes"
}
[/block]

# OpenAPI definition

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "API Settings",
    "version": "2.0"
  },
  "servers": [
    {
      "url": "https://api.telegram.org"
    }
  ],
  "security": [
    {}
  ],
  "paths": {
    "/bot{token}/setWebhook": {
      "post": {
        "summary": "setWebhook",
        "description": "Use this method to specify a url and receive incoming updates via an outgoing webhook.",
        "operationId": "setwebhook",
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "description": "Your Bot Token",
            "schema": {
              "type": "string"
            },
            "required": true
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "HTTPS url to send updates to. Use an empty string to remove webhook integration",
                    "default": "Optional"
                  },
                  "certificate": {
                    "type": "string",
                    "description": "Upload your public key certificate so that the root certificate in use can be checked. See our self-signed guide https://core.telegram.org/bots/self-signed for details.",
                    "default": "Optional",
                    "format": "binary"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": "{\n    \"ok\": true,\n    \"result\": true,\n    \"description\": \"Webhook was set\"\n}"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "example": true,
                      "default": true
                    },
                    "result": {
                      "type": "boolean",
                      "example": true,
                      "default": true
                    },
                    "description": {
                      "type": "string",
                      "example": "Webhook was set"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "400",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": "{\n    \"ok\": false,\n    \"error_code\": 400,\n    \"description\": \"[Error]: Bad webhook: [Error]: HTTPS url must be provided for webhooks\"\n}"
                  },
                  "Invalid Domain": {
                    "value": "{\n    \"ok\": false,\n    \"error_code\": 400,\n    \"description\": \"[Error]: Bad webhook: [Error]: getaddrinfo: Name or service not known\"\n}"
                  }
                },
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "ok": {
                          "type": "boolean",
                          "example": false,
                          "default": true
                        },
                        "error_code": {
                          "type": "integer",
                          "example": 400,
                          "default": 0
                        },
                        "description": {
                          "type": "string",
                          "example": "[Error]: Bad webhook: [Error]: HTTPS url must be provided for webhooks"
                        }
                      }
                    },
                    {
                      "title": "Invalid Domain",
                      "type": "object",
                      "properties": {
                        "ok": {
                          "type": "boolean",
                          "example": false,
                          "default": true
                        },
                        "error_code": {
                          "type": "integer",
                          "example": 400,
                          "default": 0
                        },
                        "description": {
                          "type": "string",
                          "example": "[Error]: Bad webhook: [Error]: getaddrinfo: Name or service not known"
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "deprecated": false,
        "x-readme": {
          "code-samples": [
            {
              "language": "php",
              "code": "use Telegram\\Bot\\Api;\n\n$telegram = new Api('BOT TOKEN');\n\n$response = $telegram->setWebhook(['url' => 'https://example.com/{token}/webhook']);\n\n// Or if you are supplying a self-signed-certificate\n$response = $telegram->setWebhook([\n  'url' => 'https://example.com/{token}/webhook',\n  'certificate' => '/path/to/public_key_certificate.pub'\n]);",
              "name": "Standalone"
            },
            {
              "language": "php",
              "code": "// Don't forget to setup a POST route in your Laravel Project.\n$response = Telegram::setWebhook(['url' => 'https://example.com/{token}/webhook']);\n\n// Or if you are supplying a self-signed-certificate\n$response = Telegram::setWebhook([\n  'url' => 'https://example.com/{token}/webhook',\n  'certificate' => '/path/to/public_key_certificate.pub'\n]);",
              "name": "Laravel"
            }
          ],
          "samples-languages": [
            "php"
          ]
        }
      }
    }
  },
  "x-readme": {
    "headers": [
      {
        "key": "User-Agent",
        "value": "Telegram Bot SDK - (https://github.com/irazasyed/telegram-bot-sdk)"
      }
    ],
    "explorer-enabled": true,
    "proxy-enabled": true
  },
  "x-readme-fauxas": true,
  "_id": "58b53b061065f9c438aa1ab4:5e509d6bfb0c6e001fb4fc66"
}
```