- Deploying a telegram bot using Cloud functions is a much simpler process than the previous 2 deployments.
- To start with, go to the Cloud Functions page and click on the
Create Function
button. - In the next page, set the
Environment
to1rst gen
and set theFunction Name
. Allow theAllow unauthenticated invocations
option, set theTrigger
toHTTP
and set theEnvironment variables
andBuild variables
. - Now, click on the
Create
button. In the next page, set theRuntime
toNode.js 14
and set theEntry point
as the function name which is exported. Set theSource code
asInline editor
and paste the code in theindex.js
file. Also update thepackage.json
file with the dependencies and then, click on theDeploy
button. - Now, the bot is deployed on the cloud functions!🥳
- But the bot is not yet available to the public. To make the bot available to the public, we need to set up the webhook. For this, first remove the webhooks present for the bot by sending the following request to the telegram bot API:
curl -X POST https://api.telegram.org/bot<token>/deleteWebhook
- Then, set the webhook by sending the following request to the telegram bot API:
curl -X POST https://api.telegram.org/bot<token>/setWebhook?url=<url>
- In the above request,
<token>
is the token of the telegram bot and<url>
is the url of the cloud function. - Now, the bot is available to the public!🥳
- You can check out the telegram bot here.