Article Directory
- foreword
- environment list
- 1. Feishu Settings
- 2. Clone the feishu-chatgpt project
- 3. Configure the config.yaml file
- 4. Run the feishu-chatgpt project
- 5. Install cpolar intranet penetration
- 6. Fixed public network address
- 7. Robot permission configuration
- 8. Create version
- 9. Create a test enterprise
- 10. Robot Test
foreword
Create a chatGPT robot in Feishu and have a conversation. In the following steps, the Git clone project is used. Git needs to be installed in advance. The cloned project is a Go language project, so the Go language environment needs to be installed in advance.
environment list
-
Git
-
Go1.20
1. Feishu Settings
When registering for Feishu for the first time, we can create a personal account
After entering, we create a Feishu企业自建项目
Then set the robot name and description, select the icon and color below
After the creation is successful, add the ability of the robot
2. Clone the feishu-chatgpt project
The feishu-chatgpt project integrates the function of calling chatgpt from Feishu. Here, the windwos system is used to clone the project using git in powershell, select the directory, and clone the project
git clone https://github.com/Leizhenpeng/feishu-chatgpt.git
then entercode目录
cd feishu-chatgpt/code
Modify the configuration file name
mv config.example.yaml config.yaml
3. Configure the config.yaml file
In the code folder of the project directory we cloned above, you can see config.yaml
the configuration file
APP ID
Open the configuration file, we can see that the first two parameters correspond to the sum of the project we created on FeishuApp Secret
Open Feishu and copy the corresponding parameters
Fill in these two parameters correspondingly to the configuration file
Then there are two more parameters below: APP_ENCRYPT_KEY
andAPP_VERIFICATION_TOKEN
Also in Feishu, click 事件与订阅
, and then we can see
The first value is not enabled, we can click refresh
Then we fill in the two values into the configuration file respectively, remember to save
After filling in the parameters of Feishu, the next step is to set the parameters of openAI in the configuration file. We need to obtain the KEY of openAI. You can go to the official website of openAI to obtain it with your own account, or there are some free websites for testing, such as https://freeopenai.xyz / This website, we can get a key, after getting it, we fill in the key value into the configuration file, remember to save the file
Open the configuration file, we can see that the first two parameters correspond to the APP ID and App Secret of the project we created on Feishu
Finally, the device needs to use a proxy. Configure the proxy in the last line. If you do not configure it, you will not be able to access the chatgpt interface, and you will not get the answer returned by chatGPT.
4. Run the feishu-chatgpt project
The first run will download the relevant required packages. In order to prevent the download from being successful, first set the proxy in go and execute the following command切换国内代理
go env -w GOPROXY=https://goproxy.cn,direct
Then 运行main.go文件
, start the project,
go run main.go
Pay attention to the path above the picture. It must be operated under the code folder of the feishu-chatgpt project. After starting, we can see the port number. The port number is:9000
After the service is started, we need to set the address for the Feishu robot to connect to our service. We are required to set an external network address instead of a LAN address.
Here we use the cpolar internal network penetration tool to map the local service under port 9000 to the public network, and it will automatically generate and return the corresponding public network address. You can use this public network address to set up the Feishu robot connection service without public network IP, no need to set up a router, and no public network server is required.
5. Install cpolar intranet penetration
cpolar official website: https://www.cpolar.com/
Visit cpolar official website, register an account, then download and install the windows version of cpolar client.
After the successful installation of cpolar intranet penetration, visit the local port 9200 [ http://localhost:9200 ] on the browser , and log in with the cpolar account.
Click Tunnel Management on the left dashboard - Create Tunnel, create an http tunnel, point to port 9000, which is the service port number on which we run main.go above
- Tunnel name: you can customize the name, be careful not to duplicate the existing tunnel name
- Protocol: select http
- Local address: 9000
- Domain name type: choose a random domain name for free
- Region: Select China VIP
click创建
After the tunnel is successfully created, click on the status on the left - online tunnel list, view the generated public network address, and then copy the address
Then open the Feishu robot, we fill in the public network address above, note that the resource path needs to be added /webhook/card
, and then click Verify
After clicking verify, there is no prompt indicating success, and we can also see the printed log in powershell
6. Fixed public network address
Since what we just created is a free random temporary tunnel, the public network address it generates will change randomly within 24 hours, which is not suitable for long-term use. So we will fix this public network address next.
Note that the cpolar package needs to be upgraded to the basic package or above, and the bandwidth corresponding to each package is different.
Log in to the background of the cpolar official website, click on the left 预留
, select 保留二级子域名
, set a second-level subdomain name, click Reserve, and copy the reserved second-level subdomain name after the reservation is successful
After the reservation is successful, copy the reserved second-level subdomain address
Access the local port 9200 [127.0.0.1:9200], log in to the cpolar web UI management interface, click on the tunnel management on the left dashboard - 隧道列表
, find the tunnel to be configured, and click on the right编辑
Modify the tunnel information, and configure the successfully reserved second-level subdomain name into the tunnel
- Domain name type: select a second-level subdomain name
- Sub Domain: Fill in the reserved sub-domain name
click更新
After the update is complete, open the online tunnel list. At this time, you can see that the public network address has changed, and the address name has also become a reserved second-level subdomain name. Copy it down
Then we open the Feishu robot, 把随机地址换成我们固定的公网地址
and click save
Then open the following 事件订阅
, also set the public network address into it, change the resource path behind /webhook/event
, and then click Save
7. Robot permission configuration
Open permission management, filter permissions, enterim:message
Then enable the following permissions in batches
- im:resource (get and upload image or file resources)
- m:message
- im:message.group_at_msg (Get all messages in the group)
- im:messagegroup_at_msg:readonly (receive @robot message event in group chat)
- im:message.p2p_msg (Get the single chat message sent by the user to the robot)
- im:messagep2p_msg:readonly (read the single chat message sent by the user to the robot)
- im:message:send_as_bot (get the message of the user @bot in the group)
- im:chat:readonly (get group information)
- im:chat (get and update group information)
Search im:resource
, open this permission
Then enter again im:chat
to enable the following two permissions
Then add the event, add the following three events
8. Create version
Click above 创建版本
, fill in the version information and update instructions
Then click below to save
After saving successfully申请线上发布
9. Create a test enterprise
Click next to Test Businesses and People, we创建一个测试企业
After creating, click关联应用
Then we switch the account and switch to the test enterprise account we created above
After switching, you can see the robot project we created, click to enter
We can see that the status has been published
Then we have to continue to set the last step, open the credential and basic information, view APPID
and APP Secret
these two values
Then replace the above two values in our configuration file. The configuration file uses the value of the Feishu personal account. Now that the test enterprise account is created, it needs to be changed to the sum of the test enterprise account APPID
.APP Secret
Restart after changing
10. Robot Test
Download Feishu, open Feishu, and select the test enterprise account we created above when logging in
then click search
Enter chat
, you can see the robot we set up, click
Then you can have a conversation, the robot reply is a bit slow, because it is an overseas interface