- Clone this repo
- Obtain
client_secret.json
as described here and add it toScheduleBot/ScheduleBot.AspHost
directory (It's neccessary for access to Google Sheets) - Running config is defined by
appsetting.{ASPNETCORE_ENVIRONMENT}.json
files, based onappsetting.json
atScheduleBot/ScheduleBot.AspHost
directory. Settings include:UseWebHook
- set uptrue
for handle requests with webhook (required specifiedWebhookUrl
param, we use Ngrok for this feature),false
for Long-pooling (request to tg-server every sec)ScheduleBot
- specify your bot api token and usernameGoogleApi
- specify your application name forclient_secret.json
and spreadsheet idNotificationsSecret
- passphrase to send notification to all bot's subscribers (to do it you need create Supergroup with someone with bot as admin, delegate him access to delete messages and write to this chat message in next format:/sendsudo key=PASSWORDHERE your text here to all
)
- Install dotnet for your platform
-
Look at this article, it makes things clear
-
After adding
client_secret.json
and requiredappsettings.{environment}.json
publish app from repocd /root/repos/itis-bot/ScheduleBot/ScheduleBot.AspHost/ dotnet publish -c Release -o /srv/dotnet/bot/
where
-o /PATH
defines path to working directory where resultScheduleBot.AspHost.dll
will appear. -
You can test build with run (default
ASPNETCORE_ENVIRIONMENT=Production
)cd /srv/dotnet/bot/ dotnet ScheduleBot.AspHost.dll
- If You don't have GUI app will fail to run, because Google API needs to authentificate app via browser (see
logs
directory). But there is little trick to walk it around, if You have only CLI. Run app on another host with GUI, authentificate yourself via browser and copy-pastesheets.googleapis.com-dotnet-quickstart.json/
directory on this GUI-host into/home/APP_USER/.credentials/
(~/.credentials/
by default) on your Linux-CLI-host. Example, on Windows, after launch, You can find it hereC:\Users\YOURUSER\Documents\.credentials\sheets.googleapis.com-dotnet-quickstart.json\
- If You don't have GUI app will fail to run, because Google API needs to authentificate app via browser (see
-
Check logs, if all right, add service.
sudo nano /etc/systemd/system/itis-bot.service
Config example:
- run as root, so
/root/.credentials/sheets.googleapis.com-dotnet-quickstart.json/
required - changed
ASPNETCORE_ENVIRIONMENT=Release
to useappsettings.Release.json
config
[Unit] Description=ASP.NET Core based telegram bot for schedule delivering [Service] WorkingDirectory=/srv/dotnet/bot ExecStart=/usr/bin/dotnet /srv/dotnet/bot/ScheduleBot.AspHost.dll Restart=always RestartSec=40 # Restart service after 40 seconds if dotnet service crashes SyslogIdentifier=itis-bot-service User=root Environment=ASPNETCORE_ENVIRONMENT=Release Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false [Install] WantedBy=multi-user.target
then
systemctl enable itis-bot.service systemctl start itis-bot.service systemctl status itis-bot.service
- run as root, so
-
Using webhook with Ngrok
- Download and unpackage ngrok (signup required, see website)
wget "https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip" unzip ./ngrok-stable-linux-amd64.zip ./ngrok authtoken YOUR_NGROK_TOKEN_HERE
- Run it in background
./ngrok http 8443 -region=eu > /dev/null &
- Find up https tunnel address
curl localhost:4040/api/tunnels > bla-bla { "public_url":"https://XXXXXX.eu.ngrok.io","proto":"https", } bla-bla
- Add address to
appsettings.{ASPNETCORE_ENVIRONMENT}.json
(Release
here) and enable Webhook. Don't forget addapi/update
uri part to webhook url.
nano ~/repos/itis-bot/ScheduleBot/ScheduleBot.AspHost/appsettings.Release.json
{ "UseWebHook": true, .... "ScheduleBot": { .... "WebhookUrl": "https://XXXXXX.eu.ngrok.io/api/update" }, ... }
-
Stop service, rebuild and run again.
/property option used only for running under core 2.1 sdk: SO answer
cd ~/repos/itis-bot/ScheduleBot/ScheduleBot.AspHost/ systemctl stop itis-bot.service dotnet publish -c Release -o /srv/dotnet/bot/ /property:PublishWithAspNetCoreTargetManifest=false systemctl start itis-bot.service
Important for developers in Russian Federation: please ensure You have access to telegram.org directly or througth system VPN. If you'r using system proxy, it's not guaranteed that bot will serve requests. If you have Fiddler, it could help to bypass blocks, when running (with system proxy). If you have a suggestion, how to reach tg.org on your local while development, welcome to #9
-
Set up environment
- Power-Shell
$Env:ASPNETCORE_ENVIRONMENT = "Development"
- Git-bash
$ ASPNETCORE_ENVIRONMENT=Development
- cmd
> set ASPNETCORE_ENVIRONMENT=Development
-
At repo:
> cd .\ScheduleBot\ScheduleBot.AspHost > dotnet build -c Release > cd .\bin\Release\netcoreapp2.0 > dotnet ScheduleBot.AspHost.dll
-
Using webhook with Ngrok
- in progress