npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

gomtin

v1.0.3

Published

n8n custom node để gom tin nhắn từ nhiều trigger với Redis và intelligent delay

Downloads

3

Readme

Banner image

gomtin

🚀 n8n custom node để gom tin nhắn từ nhiều trigger với Redis và intelligent delay

Giải quyết vấn đề tin nhắn rời rạc trong chatbot/webhook bằng cách gom nhiều tin nhắn thành một với chiến lược chờ thông minh.

📦 Cài đặt

npm install gomtin

Sau khi cài đặt, restart n8n để load nodes mới.

⚡ Tính năng chính

  • Gom tin nhắn thông minh: Tự động gom nhiều tin nhắn rời rạc thành một
  • 2 chiến lược xử lý: Smart Wait và Immediate on Complete
  • Real-time waiting: Node thật sự chờ, không cần external scheduler
  • Redis support: Hỗ trợ Redis local và cloud (Upstash, Redis Cloud)
  • Connection testing: Node test kết nối Redis riêng biệt
  • Flexible keys: Hỗ trợ user ID, group ID, hoặc kết hợp

🎯 Vấn đề giải quyết

Trước khi sử dụng:

Trigger 1: "Xin"     → Xử lý ngay → Response "?"
Trigger 2: "chào"    → Xử lý ngay → Response "?"
Trigger 3: "bạn!"    → Xử lý ngay → Response "?"

Sau khi sử dụng:

Trigger 1: "Xin"     → Lưu & chờ
Trigger 2: "chào"    → Lưu & chờ
Trigger 3: "bạn!"    → Lưu & chờ 5s → Gom: "Xin chào bạn!" → Response

🚀 Bắt đầu nhanh

Bước 1: Setup Redis

Option A - Upstash Redis (Khuyến nghị cho người mới):

  1. Đăng ký tại upstash.com (free tier)
  2. Tạo Redis database mới
  3. Copy connection string dạng: redis://default:[email protected]:6379

Option B - Redis local:

# Docker
docker run -d -p 6379:6379 redis:alpine

# macOS
brew install redis && redis-server

# Ubuntu
sudo apt install redis-server

Bước 2: Tạo Credentials

  1. Trong n8n, vào CredentialsNewRedis API
  2. Chọn connection type:
    • Connection String: Paste connection string từ Upstash
    • Host & Port: Nhập localhost:6379 cho Redis local

Bước 3: Test Connection

  1. Thêm node Redis Connection Test
  2. Chọn credentials vừa tạo
  3. Chọn Complete Test và execute
  4. Xem kết quả: ✅ Connection successful!

Bước 4: Basic Workflow

[Manual Trigger] → [Redis Message Aggregator] → [Set] (để xem kết quả)

Cấu hình Redis Message Aggregator:

  • Key: user123 (hoặc bất kỳ string nào)
  • Message Content: Xin chào!
  • Wait Time: 5 (giây)
  • Strategy: Smart Wait

📚 Chi tiết Nodes

Redis Message Aggregator

Node chính để gom tin nhắn với 2 chiến lược đơn giản:

🧠 Smart Wait (Khuyến nghị)

Chờ thông minh - chỉ output khi chắc chắn không có tin nhắn mới.

Khi nào dùng: Chatbot, webhook nhận tin nhắn liên tiếp

Ví dụ:

// Input: 3 tin nhắn với key "user123"
// - "Xin" (10:00:00)
// - "chào" (10:00:03)
// - "bạn!" (10:00:06)

// Output sau 5 giây không có tin mới (10:00:11):
{
  "status": "messages_aggregated",
  "key": "user123",
  "aggregatedMessage": "Xin chào bạn!",
  "messageCount": 3,
  "trigger": "smart_timeout"
}

🎯 Immediate on Complete

Trả về ngay khi phát hiện tin nhắn kết thúc bằng từ được định nghĩa.

Khi nào dùng: Khi muốn response nhanh với những từ kết thúc cụ thể

Cấu hình:

  • End Words: xong, rồi, nhé, ok, done (ngăn cách bởi dấu phẩy)

Ví dụ:

// End Words: "xong, rồi, nhé"
"Xin chào"     → Chưa hoàn chỉnh → Lưu & chờ
"bạn nhé"      → Hoàn chỉnh (kết thúc bằng "nhé") → Output ngay: "Xin chào bạn nhé"

Redis Connection Test

Node để test và troubleshoot Redis connection.

Test Types:

  • Basic Connection: Chỉ test PING
  • Read/Write Test: Test SET/GET/DEL
  • Server Info: Lấy thông tin Redis server
  • Complete Test: Chạy tất cả tests above

🔧 Cấu hình nâng cao

Key Patterns

Sử dụng key linh hoạt cho các tình huống khác nhau:

// Chat 1-1
key = 'user_123';

// Group chat
key = 'group_456';

// User trong group cụ thể
key = 'user_123_group_456';

// Session based
key = 'session_abc123';

// Multi-tenant
key = 'tenant_A_user_123';

Redis Options

Tùy chỉnh connection cho performance tốt hơn:

  • Connection Timeout: 5000ms (mặc định)
  • Command Timeout: 3000ms (mặc định)
  • Max Retries: 1 (mặc định)

Strategy Selection Guide

| Strategy | Use Case | Output Timing | Best For | | --------------------- | ----------------- | ------------------------- | ----------------- | | Smart Wait | Chatbot responses | Sau X giây no new message | Real-time chat | | Immediate on Complete | Quick responses | Khi detect end words | Fast interactions |

💡 Workflow Examples

Example 1: Chatbot với Smart Wait

[Webhook] → [Redis Message Aggregator] → [OpenAI/ChatGPT] → [Response]

Cấu hình:

  • Key: {{$json.userId}} (từ webhook payload)
  • Message: {{$json.message}}
  • Strategy: Smart Wait
  • Wait Time: 3 giây

Example 2: Quick Response với End Words

[Webhook] → [Redis Message Aggregator] → [Filter: Complete Messages] → [Processing]

Cấu hình:

  • Key: {{$json.groupId}}_{{$json.userId}}
  • Strategy: Immediate on Complete
  • End Words: xong, rồi, nhé, ok, done

🔍 Troubleshooting

❌ "Connection failed"

  1. Dùng Redis Connection Test node để kiểm tra
  2. Verify credentials và connection string
  3. Check firewall/network access

❌ "Key và Message Content là bắt buộc"

  • Đảm bảo cả 2 fields đều có giá trị
  • Kiểm tra expressions nếu dùng dynamic values

❌ Không có output

  • Cả 2 strategies đều output khi có kết quả
  • Check Redis có tin nhắn không bằng Redis Connection Test
  • Verify end words có match không (cho Immediate strategy)

❌ Tin nhắn không gom được

  • Verify cùng Key được sử dụng
  • Check Wait Time có phù hợp không
  • Ensure Redis connection stable

📝 API Reference

Input Parameters

| Parameter | Type | Required | Description | | -------------- | ------ | -------- | --------------------------------------------------------------- | | key | string | ✅ | Key để gom tin nhắn | | messageContent | string | ✅ | Nội dung tin nhắn | | waitTime | number | ✅ | Thời gian chờ (giây) | | strategy | string | ✅ | Chiến lược xử lý | | endWords | string | ❌ | Từ kết thúc ngăn cách bởi dấu phẩy (chỉ cho Immediate strategy) |

Output (khi status = 'messages_aggregated')

{
  "status": "messages_aggregated",
  "key": "user123",
  "aggregatedMessage": "Xin chào bạn!",
  "messageCount": 3,
  "originalMessages": [
    {"content": "Xin", "timestamp": 1234567890},
    {"content": "chào", "timestamp": 1234567893},
    {"content": "bạn!", "timestamp": 1234567896}
  ],
  "trigger": "smart_timeout",
  "aggregatedAt": "2024-01-01T10:00:11.000Z"
}

🛡️ Security & Performance

  • TTL automatic: Tin nhắn tự động expire
  • Lock mechanism: Tránh race conditions
  • Connection pooling: Efficient Redis usage
  • Error handling: Comprehensive error messages

🤝 Support

📄 License

MIT © Hoang Thanh Nga


⭐ Nếu package này hữu ích, đừng quên star trên GitHub!