Skip to content

fanlino/AutoBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Bot

Creating Telegram Bot

You can clone this repository to create this application.

app.py is the file which does all the work.

As we are using sensitive information like tokens and secrets, we will use Kubernetes Secrets to store these and access them in the code

  • chat_token - Chat Token
  • chat_id - ChatRoom ID

Start by encoding all the keys and secrets

echo -n 'chat_token' | base64
EncodedChatToken==

echo -n 'chat_id' | base64
EncodedChatId==

Create a new secrets.yaml file and add the encoded strings as data. We would be accessing these secrets from our code. Refer to our documentation on accessing secrets in Fission from code.

apiVersion: v1
kind: Secret
metadata:
  namespace: default
  name: telegram-secret
data:
  chat_token: EncodedChatToken==
  chat_id:  EncodedChatId==
type: Opaque

Deploy the secret using kubectl apply -f secrets.yaml

Steps to Execute

Create a Python environment

fission environment create --name python --image fission/python-env-3.10 --builder fission/python-builder-3.10

Create a zip archive as sample.zip archive by executing package.sh script

./package.sh

Create a Package

fission package create --name autobot-pkg --sourcearchive pkg.zip --env python --buildcmd "./build.sh"

Create the tweetbot fission function

fission fn create --name autobot --pkg autobot-pkg --env python --entrypoint "app.main" --secret telegram-secret

Test and Execute

Before you run the application, send a tweet to the user whom you're tracking. Test the function by executing the following command:

fission fn test --name autobot

You should see that your bot has replied to the latest tweet that mentioned you. It has also sent a note in your slack workspace.

There are multiple ways to automate this, in this case we are using Fission Time Trigger to execute the function every 1m. You can change this according to your needs.

fission timer create --name minute --function autobot --cron "@every 1m"

Fission Spec

fission spec init
fission environment create --name python --image fission/python-env-3.10 --builder fission/python-builder-3.10 --spec
fission package create --name autobot-pkg --sourcearchive pkg.zip --env python --buildcmd "./build.sh" --spec
fission fn create --name autobot --pkg autobot-pkg --entrypoint "app.main" --secret telegram-secret --spec
fission timer create --name minute --function autobot --cron "@every 1m" --spec

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published