In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to use Serverless+ Flying Book to build your personalized message reminder system, I believe that many inexperienced people are at a loss about this. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
I. Preface
In our daily work, study and life, we may encounter the following situations:
One of the servers I managed was down, but it was not reminded in time, resulting in a loss of business.
Some websites that they really want to register are quietly open to register, but they do not know in time, so they can only continue to wait aimlessly.
……
If we take the time to pay attention to everything, we are bound to run out of time, so is there any way to get these messages together and push them in time? Here I would like to recommend a solution, that is to use Serverless + Flying Book to create their own personalized message reminder system.
II. Preparatory work
First sign up for a flying book account, and then log in in the flying book web page
Open the Feishu open platform, click create enterprise self-built application, enter the application name and application subtitle, and then click OK to create
Click on the newly created application in the list of self-built applications, and record App ID and App Secret
Second, write code
Create a new project directory locally with an arbitrary name. Take feishu-notify as an example.
Create three files: .env, index.py and serverless.yml
Encode as follows
.envTENCENT _ SECRET_ID=AKID**TENCENT_SECRET_KEY=**
Note: the TENCENT_SECRET_ID and TENCENT_SECRET_KEY here can be obtained from the access key in the Tencent Cloud console. If you do not have a key, you need to create a new one.
Serverless.ymlmyFunction: component: "@ serverless/tencent-scf" inputs: name: feishu-notify-py codeUri: ". /" handler: index.main_handler runtime: Python3.6 region: ap-guangzhou description: My Serverless Function Used to Notify Myself memorySize: 128 events:-apigw: name: serverless parameters: protocols:-https endpoints:-path: "/" method: POST
Note: you can click here to view a list of all available attributes in serverless.yml
Index.pydef main_handler (event, context): import requests import json print (event) CONFIG = {"app_id": "*" "app_secret": "* *"} # myauth if 'myauth' not in event [' queryString'] or event ['queryString'] [' myauth']! = 'feishu1': return' forbidden' # Get content postContent = event ['body'] try: postContent = json.loads (postContent) except: return 'error in json_loads (line: 19)' if 'content' not in postContent: return' invalid params' content = postContent ['content'] # Get tenant_access_token try: res = requests.post (' https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal/', {"app_id": CONFIG ['app_id'] "app_secret": CONFIG ['app_secret']}) except: return' error in get_tenant_access_token' data = json.loads (res.text) if data ['code']! = 0: return data [' msg'] token = data ['tenant_access_token'] # Get chat_id try: res = requests.get (' https: / / open.feishu.cn/open-apis/chat/v4/list' Headers= {'Authorization':' Bearer% s'% (token)}) except: return 'error in get_chat_id' data = json.loads (res.text) if data [' code']! = 0: return data ['msg'] groupList = data [' data'] ['groups'] myGroupId = groupList [0] [' chat_id'] # Send message Try: res = requests.post ('https://open.feishu.cn/open-apis/message/v4/send/', Json= {"chat_id": myGroupId, "msg_type": "text", "content": {"text": content}}, headers= {'Authorization':' Bearer% s'% (token) 'Content-Type':' application/json'}) except: return 'error in send message' data = json.loads (res.text) if data [' code']! = 0: return data ['msg'] return' success'
With regard to index.py, there are a few points to explain:
The app_id and app_secret entries in the code need to fill in the App ID and App Secret in preparing the work record.
Finally, we use the POST method to send the message.
When calling, we also need to add? myauth=feishu1 to the query for simple verification to prevent others from sending it, such as https://service-********-**********.**.apigw.tencentcs.com/release/?myauth=feishu1
III. Deploy Serverless services
Install Serverless through npm
$npm install-g serverless
Deploy through the serverless command and add the-- debug parameter to view the information in the deployment process
$serverless-debug
Obtain the URL of the API gateway from the terminal
Get the URL of the API gateway
IV. Online application
Go back to the Flying Book Open platform and click on the newly created application in the list of self-built applications.
Click Application function-Robot, click to enable Robot
Click version Management and release-create a version, and refer to the following figure for configuration (do not click Save first)
Click Edit in the availability status, select all employees, and then click Save
Click to apply for release
Click on the profile picture of the web version of Flying Book to enter the background of Flying Book Management.
Click Workbench-apply Audit, and then click Audit
Click yes
5. Call the interface
Request method: POST
Request address: the URL of the APIGateway obtained above
Request Header:
Parameter type required / optional indicates default value instance Content-Typestring required Content-Type
Application/json
Request Query:
Parameter type required / optional description default value instance myauthstring required simple verification
Feishu1
Request Body:
{"content": "fill in the message you want to send here"} VI. Effect
For convenience, use the Chrome browser plug-in Talend API Tester to call
As you can see, the news of Fei Shu was pushed in time.
In fact, the use of flying books can achieve more than that, I believe that smart you will be able to develop more fun applications.
After reading the above, have you mastered how to use Serverless+ Flying Book to build your personalized message reminder system? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.