| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Google Cloud Function triggered by Pub/Sub message being sent on certain topic.
This function is simple example of cloud function with Pub/Sub trigger type which send message to Slack channel on behalf of the user(Bot). User will be defined by user token from Slack.
We will use test slack channel test-webshop-cf to test how this function works.
Runtime: Node.js
git clone git@github.com:lemon57/cloud-function-pubsub-slack-msg.git
gcloud functions deploy <CF_NAME> \
--trigger-resource <PUB_SUB_TOPIC_NAME> \
--trigger-event google.pubsub.topic.publish \
--region=<REGION_NAME> \
--runtime=<CF_RUNTIME>
Replace PUB_SUB_TOPIC_NAME by your topic name. Define your own.
Replace REGION_NAME by region of current project.
Replace CF_RUNTIME by actual runtime, in our case is nodejs16
gcloud functions describe <CF_NAME> --region=<REGION_NAME>
gcloud functions call <CF_NAME> --data '{"data":"R29vZ2xlIGNsb3VkIGZ1bmN0aW9uIHdvcmtzaG9w"}'
This string R29vZ2xlIGNsb3VkIGZ1bmN0aW9uIHdvcmtzaG9w base64 encoded. To use your specific message and make it base64 encoded you can use this resource base64encode
or by sending message to certain topic by command:
gcloud pubsub topics publish projects/<PROJECT_NAME>/topics/<TOPIC_NAME> --message Hello
Replace PROJECT_NAME by our current boozt project name. Replace TOPIC_NAME by topic name which you find by following command:
gcloud pubsub topics list | grep <KEY_WORD_FROM_TOPIC_NAME>
Replace KEY_WORD_FROM_TOPIC_NAME by topic name which you just recently created when deploy the function.
gcloud functions logs read --execution-id=<EXECUTION-ID> --region=<REGION_NAME>
Take EXECUTION_ID from the output after executing these commands: gcloud functions call or gcloud pubsub topics publish.
Enjoy 🎆
| Back | FazBrowse Home | New Git URL |