Skip to content

Knative and Camel-K app which translates Telegram messages via Google Translate API

Notifications You must be signed in to change notification settings

lance/telegram-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Knative and Camel-K Telegram Translate Bot Example

This demo converts Telegram messages into English using Camel-K and Knative functions.

It uses a Camel-K Kamelet to periodically poll Telegram for messages. The Kamelet converts each message into a CloudEvent, sending it to the default Knative Broker. A translate function receives these events via a Trigger between the Broker and the function which filters for these types of events.

The translate function uses the Google Translation API is used to convert the message text to English, and the result is returned to the broker as data in a new translation CloudEvent.

The broker has two additional triggers that respond to these translation events. One forwards the event to a viewer function, which simply displays the event on the console so that we can see if things are behaving as expected. The other trigger sends the event to a responder function, which responds to the message in the Telegram chat with the translation.

System diagram

Prerequisites

Steps

  • Ensure your Google Translation API key is correctly set in translate/service-account-file.json
  • Create a Kubernetes secret containing your Telegram API key
kubectl create secret generic telegram --from-literal=API_KEY=<apikey>
  • Install a default Knative Broker
kn broker create default
  • Deploy the functions
func deploy -p viewer
func deploy -p translate
func deploy -p responder
  • Create the Telegram->Translate trigger
kn trigger create telegram-trigger -s translate --filter type=telegram.source
  • Create the Translation->Viewer trigger
kn trigger create translate-trigger -s viewer --filter type=knative.function.translation
  • Create the Translation->Responder trigger
kn trigger create responder-trigger -s responder --filter type=knative.function.translation
  • Install the Kamelet
kubectl apply -f resources/telegram-binding-v1.yaml
  • Send a Telegram message to your bot channel

  • Check the logs

k logs -l app=viewer -f
k logs -l app=responder -f
k logs -l app=translate -f
  • Cleanup
./resources/teardown.sh

About

Knative and Camel-K app which translates Telegram messages via Google Translate API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published