update jpg path

This commit is contained in:
tigeren 2023-03-11 19:39:46 +08:00
parent 8166c27db6
commit ea0eb07a5d
1 changed files with 7 additions and 7 deletions

View File

@ -17,13 +17,13 @@ Let's start easy, fork/clone this repository. This repo provides all code to cre
In the root of this repository you see a `.env.example` file. Rename this file to `.env`. This is where your secret Telegram bot token will be stored on your local machine. For now leave the value as is, we will replace it with the real value later on.
## Step 2: Create an Azure Function App
<img src="/tigeren/chat-bot/src/branch/main/docs/create-function-app.jpg" alt="Create Azure Function App" align="right" width="400" />
<img src="./docs/create-function-app.jpg" alt="Create Azure Function App" align="right" width="400" />
First step is creating a Node.js Azure Function App. You can run through the default setup with all the settings you like. The only thing I advice is running it on __Windows__ OS. This might seem unnecessary but I found Windows Azure Function Apps to run Timer triggers more consistent than on a Linux OS.
When asked for a plan type, select __Consumption (Serverless)__. By default Apps running on a Consumption plan will timeout after a maximum 10 minutes of inactivity, but we will use a Timer trigger Function App to fix that. This Timer trigger is a second Function that is deployed, which is set up to trigger every 10 minutes. This will make sure the bot never gets a timeout without using a more expensive plan type, pretty awesome!
<img src="/tigeren/chat-bot/src/branch/main/docs/publish-profile.jpg" alt="Download publish profile" align="right" width="400" />
<img src="./docs/publish-profile.jpg" alt="Download publish profile" align="right" width="400" />
After creating your Node.js Azure Function App, go to the Function App resource and download the __publish profile__. We will need that later when configuring our automatic deployment.
@ -32,17 +32,17 @@ Next thing we will have to configure is our `AzureWebJobsStorage` connection str
## Step 3: Registering the bot
In order to register your Telegram bot you need to talk to the [BotFather](https://core.telegram.org/bots#6-botfather) on Telegram.
<img src="/tigeren/chat-bot/src/branch/main/docs/botfather.jpg" alt="BotFather" align="center" width="600" />
<img src="./docs/botfather.jpg" alt="BotFather" align="center" width="600" />
By typing `/newbot` your new bot will be registered. The __name__ that you enter is displayed in contact details and elsewhere. The __Username__ as a short name, to be used in mentions an t.me links. This name __must__ end in 'bot', e.g. 'tetris_bot' or 'TetrisBot'.
When done registering the bot you'll get a token to access the HTTP API.
<img src="/tigeren/chat-bot/src/branch/main/docs/botfather-done.jpg" alt="BotFather" align="center" width="600" />
<img src="./docs/botfather-done.jpg" alt="BotFather" align="center" width="600" />
This access token is what should be placed as a value of the `BOT_TOKEN` key in your `.env` file in the root of this project. Next to that, the `BOT_TOKEN` should also be registered as an Application setting in your Function App configuration.
<img src="/tigeren/chat-bot/src/branch/main/docs/bot-token-configuration-azure.jpg" alt="Azure Application settings" align="center" width="600" />
<img src="./docs/bot-token-configuration-azure.jpg" alt="Azure Application settings" align="center" width="600" />
While in the Application Settings window we should also add a `WEBHOOK_ADDRESS` setting. The value should be the Function App URL like so: https://{your-function-name}.azurewebsites.net/api/bot.
@ -55,7 +55,7 @@ Within the project I used a GitHub Action to build and deploy the code to the Az
1. In `.github/workflows/main.yml` we need to set the `AZURE_FUNCTIONAPP_NAME` variable. This should be the name of your __Azure Function App__.
2. On GitHub go to your repository Settings page, and navigate to the Secrets tab:
<img src="/tigeren/chat-bot/src/branch/main/docs/github-actions-secrets.jpg" alt="GitHub Secrets" align="center" />
<img src="./docs/github-actions-secrets.jpg" alt="GitHub Secrets" align="center" />
Create a secret with `AZURE_FUNCTIONAPP_PUBLISH_PROFILE` as the name, and the content of the __publish-profile__ file we downloaded earlier. Just copy/paste the entire content into the Value field. This publish profile will make sure the GitHub Action deploys the code to the correct Azure Function App.
If everything is configured correctly a GitHub Action should now run after every commit to your repository. It automatically deploys your code to the Azure Function App, so all you have to do is push changes to your repository to update the bot!
@ -65,7 +65,7 @@ All the setup should be done by now, let's test the bot!
# Testing the bot
Exciting, the bot should be up and running by now! Let's find the bot on Telegram (BotFather sent your the t.me link to your bot in the same message as the access token) and try sending it a `/hello` command. If everything went well you should get a response as follows:
<img src="/tigeren/chat-bot/src/branch/main/docs/bot-response.jpg" alt="Bot response" align="center" width="600" />
<img src="./docs/bot-response.jpg" alt="Bot response" align="center" width="600" />
Hooray, you setup your own Telegram bot!