集成n8n:构建银行贷款助手
概述
银行贷款助手是一个智能服务系统,旨在简化商业贷款的咨询、申请和管理流程。通过结合OneAI的智能问答能力和n8n的工作流自动化功能,为用户提供全面的贷款服务体验。
业务价值
技术亮点
系统架构
核心流程
贷款申请工作流
交互时序
交互示例
用户向助手咨询商业贷款相关问题
用户申请商业贷款,引导用户提供必要的信息
正式提交贷款申请,取得贷款申请单号
I want to apply for a business loan.
Company Name: Example Technology Co., Ltd
Contact Person: John Doe
Loan Amount: 200,000
Loan Term: 1 year
Purpose: For expanding production scale and purchasing new equipment
符合条件,银行经理收到邮件进行贷款审批
查询审批进度(审批中)
查询审批进度(审批通过)
用户的贷款申请金额过大(超过商业贷款政策中的最大贷款金额),自动拒绝并告知原因
I want to apply for a business loan.
Company Name: Example Technology Co., Ltd
Contact Person: John Doe
Loan Amount: 200,000,000,000
Loan Term: 1 year
Purpose: For expanding production scale and purchasing new equipment
用户的贷款申请用途不合规(房地产投资),自动拒绝并告知原因
I want to apply for a business loan.
Company Name: Example Technology Co., Ltd
Contact Person: John Doe
Loan Amount: 200,000
Loan Term: 1 year
Purpose: Real estate investment
准备工作
如果要完整运行本示例,请在开始构建之前完成以下准备工作:
- OneAPI要求
- 部署n8n
- 部署PostgreSQL数据库
- n8n Credentials配置
OneAI版本
- 建议先升级到3.2_u4或以上版本,前端也升级到配套的最新版本
部署n8n
请查阅文档:n8n集成
- 参考 '部署n8n',完成n8n的部署。
- 参考 'n8n 调用OneAI API',完成OneAI社区节点的安装。
部署PostgreSQL数据库
如果您在部署n8n时已经创建了PostgreSQL数据库,可以直接使用该数据库,无需额外部署。
请在n8n所在网络环境中部署一个PostgreSQL数据库实例。部署完成后,请妥善记录以下信息:
- 数据库连接地址
- 数据库用户名
- 数据库密码
接下来,请在PostgreSQL中执行以下SQL脚本创建贷款申请表:
CREATE TABLE loan_applications (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
company_name VARCHAR(255) NOT NULL,
contact_person VARCHAR(100) NOT NULL,
loan_amount DECIMAL(15, 2) NOT NULL,
loan_term VARCHAR(50) NOT NULL,
purpose TEXT,
application_date TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
status VARCHAR(50) NOT NULL DEFAULT 'Pending Review',
review_notes TEXT,
assigned_reviewer VARCHAR(100),
review_date TIMESTAMP WITH TIME ZONE,
approval_date TIMESTAMP WITH TIME ZONE,
rejection_reason TEXT,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
n8n Credentials配置
本示例需要配置以下凭证,请在n8n Credentials中进行配置:
凭证类型 | 用途说明 | 配置示例 |
---|---|---|
SMTP account | 用于发送贷款审批相关的邮件通知,请确保已准备好邮件账号和SMTP服务器信息 | ![]() |
Postgres account | 用于存储和查询贷款申请记录,以及更新申请状态 | ![]() |
OneAI account | 用于调用OneAI平台的API接口 | ![]() |
Header Auth account | 用于为Workflow添加安全认证机制 | ![]() |
Azure Open AI account | 用于调用Azure OpenAI模型 | ![]() |
完整Credentials
开始构建
以下是构建贷款助手的主要步骤:
- 初始化知识空间
- 创建贷款申请工作流
- 创建贷款查询工作流
- 添加技能
- 配置Chatbot
初始化知识空间
在OneAI的知识空间管理界面中,进行知识空间的创建。
1、创建知识空间 | 2、文件设置 |
---|---|
![]() | ![]() |
将贷款政策的说明资料上传至知识空间,并确保它能够成功索引。
贷款政策文档示例
# Commercial Loan Policy
## Loan Amount and Term Regulations
- Minimum loan amount: $100,000 USD
- Maximum loan amount: $10,000,000 USD
- Loan terms are categorized as follows:
- Short-term: 6 months to 1 year
- Medium-term: 1 to 3 years
- Long-term: 3 to 5 years
## Permitted Loan Purposes
The following are approved uses for commercial loans:
- Purchasing equipment or raw materials
- Expanding production scale
- Technical improvement or innovation
- Working capital requirements
## Prohibited Loan Purposes
Loans cannot be used for the following:
- Financial investments (stocks, futures, etc.)
- Real estate speculation
- Repaying loans from other financial institutions
- Any activities prohibited by laws and regulations
创建贷款查询工作流
创建工作流,命名为Query Application Process
,状态设置为Active
。
通过Import from file
导入此工作流:Query Application Process Workflow
导入工作流
导入后的工作流
修改与检查
- 每个节点的Credential配置是否正确,需指向前面配置的Credentials
测试
- 通过n8n提供的mock data和Test workflow功能进行测试,确保流程能够正确执行
通过Webhook节点获取Path并进行保存
创建贷款申请工作流
创建工作流,命名为Loan Application
,状态设置为Active
。
通过Import from file
导入此工作流:Loan Application Workflow
导入后
检查与调整
- 每个节点的Credential配置是否正确,需指向前面配置的Credentials
- 修改邮件节点的发件人以及收件人邮箱
测试
- 通过n8n提供的mock data和Test workflow功能进行测试,确保流程能够正确执行
通过Webhook节点获取Path并进行保存
添加技能
添加贷款进度查询技能Query Loan Application
- 如果n8n工作流设置了HTTP Header Auth,请在技能的Request header处填写对应的Header Auth凭证
- 注意将OpenAPI Schema中的
{n8n_domain}
替换为n8n的实际域名、{path}
替换为前面保存的Webhook Path
OpenAPI Schema示例
点击查看完整代码
{
"openapi": "3.0.3",
"info": {
"title": "Query Loan Application",
"version": "1.0.0"
},
"servers": [
{
"url": "https://{n8n_domain}"
}
],
"paths": {
"/webhook/{path}": {
"get": {
"operationId": "queryLoanApplication",
"summary": "Query Loan process, status",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"applicationId": {
"type": "string",
"description": "Loan Application Id"
}
},
"required": [
"applicationId"
]
}
}
}
},
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"application_id": {
"type": "string",
"description": "Unique Application ID"
},
"companyName": {
"type": "string",
"description": "Company Name"
},
"contactPerson": {
"type": "string",
"description": "Contact Person Name"
},
"loanAmount": {
"type": "number",
"description": "Loan Amount"
},
"loanTerm": {
"type": "string",
"description": "Loan Term"
},
"purpose": {
"type": "string",
"description": "Loan Purpose"
},
"application_date": {
"type": "string",
"format": "date-time",
"description": "Date when the loan application was submitted"
},
"status": {
"type": "string",
"description": "Current status of the loan application"
},
"review_notes": {
"type": "string",
"description": "Notes from the reviewer about the application"
},
"assigned_reviewer": {
"type": "string",
"description": "Name of the person assigned to review the application"
},
"review_date": {
"type": "string",
"format": "date-time",
"description": "Date when the application was reviewed"
},
"approval_date": {
"type": "string",
"format": "date-time",
"description": "Date when the application was approved"
},
"rejection_reason": {
"type": "string",
"nullable": true,
"description": "Reason for rejection if the application was rejected"
},
"created_at": {
"type": "string",
"format": "date-time",
"description": "Timestamp when the record was created"
},
"updated_at": {
"type": "string",
"format": "date-time",
"description": "Timestamp when the record was last updated"
}
},
"required": [
"application_id",
"companyName",
"contactPerson",
"loanAmount",
"loanTerm",
"purpose",
"status",
"application_date",
"created_at",
"updated_at"
]
}
}
}
}
}
}
}
}
}
添加贷款申请技能Loan Application
- 如果n8n工作流设置了HTTP Header Auth,请在技能的Request header处填写对应的Header Auth凭证
- 注意将OpenAPI Schema中的
{n8n_domain}
替换为n8n的实际域名、{path}
替换为前面保存的Webhook Path
OpenAPI Schema示例
点击查看完整代码
{
"openapi": "3.0.3",
"info": {
"title": "Loan Application",
"version": "1.0.0"
},
"servers": [
{
"url": "https://{n8n_domain}"
}
],
"paths": {
"/webhook/{path}": {
"post": {
"operationId": "loanApplication",
"summary": "Loan Application",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"companyName": {
"type": "string",
"description": "Company Name"
},
"contactPerson": {
"type": "string",
"description": "Contact Person Name"
},
"loanAmount": {
"type": "number",
"description": "Loan Amount"
},
"loanTerm": {
"type": "string",
"description": "Loan Term"
},
"purpose": {
"type": "string",
"description": "Loan Purpose"
}
},
"required": [
"companyName",
"contactPerson",
"loanAmount",
"loanTerm",
"purpose"
]
}
}
}
},
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"application_id": {
"type": "string",
"description": "Unique Application ID"
},
"companyName": {
"type": "string",
"description": "Company Name"
},
"contactPerson": {
"type": "string",
"description": "Contact Person Name"
},
"loanAmount": {
"type": "number",
"description": "Loan Amount"
},
"loanTerm": {
"type": "string",
"description": "Loan Term"
},
"purpose": {
"type": "string",
"description": "Loan Purpose"
}
},
"required": [
"application_id",
"companyName",
"contactPerson",
"loanAmount",
"loanTerm",
"purpose"
]
}
}
}
}
}
}
}
}
}
配置Chatbot
填写Code、名称、描述等基本信息。
欢迎语可通过[]
放置一些快捷提问
示例
Hello, I am the SWO Bank Loan Assistant. How can I help you today?
[I would like to know the maximum amount for a business loan]
[I want to apply for a business loan]
[I want to check the status of my loan application]
对话设置
- 模型,建议采用
gpt-4.1
- 上下文数量,调整至最大
- 建议问题,关闭
- Prompt,注意引导技能的调用
示例
You are SWO Bank's intelligent loan assistant, equipped with extensive loan knowledge and process guidance capabilities. You will help users complete the following three tasks professionally and accurately based on knowledge base content:
### Your responsibilities include the following three core skills:
### Skill 1: Loan Policy Query
* When users ask questions about loan policies, requirements, or processes, use the `searchHybrid` function to search in the knowledge base.
* If relevant information is found, please **accurately quote the content** in your response.
* If no relevant information is found, please reply: **"No relevant information found. Please contact bank staff."**
* **Prohibited** from making up content or answering based on common sense.
### Skill 2: Loan Application
- When users wish to apply for a loan, please guide them to provide the following information:
Loan application information:
* Company Name
* Contact Person
* Loan Amount
* Loan Term
* Purpose
- After the user provides complete information, call the `loanApplication` function to initiate the loan application and inform the user of the returned application ID (application_id).
### Skill 3: Loan Progress Query
* When users wish to check loan progress, call the `queryLoanApplication` function.
* Guide users to provide the necessary loan number.
* When returning results, inform users about the loan review progress, approval or rejection reasons, and approval time, ensuring content is concise, accurate, and professional.
### Usage Principles
* All answers must be based on knowledge base content or user input, no fabrication allowed.
* Always maintain professional, clear, and polite expression.
* Please do not output superfluous hyperlinks, function names, or square brackets in your answer.
* If there are cited documents, please embed them in the answer in markdown link format at the appropriate location.
* If user's request is unclear, guide them to choose one of the following operations:
* Learn about loan policies
* Initiate loan application
* Check loan progress
技能插件
添加Loan Application以及Query Loan Application技能
知识来源
- 知识库,开启
- 知识空间,选择刚才创建的知识空间
- 检索策略,选择智能检索
- 查看引用,开启