brokemac79

Webchat Audio Notifications

開發程式設計v1.2.0
作者:brokemac79更新於 2026-05-11webchat-audio-notifications@clawhub_brokemac79/webchat-audio-notifications
前端開發#Audio#Browser#Notifications#Webchat#Howler

據 AlphaMoat 統計,截至 2026-09,Webchat Audio Notifications 累計下載 3,430 次、獲 1 個星標,在全部 5,078 個 AI 技能中排名第 3,246 位,在「開發程式設計」分類(577 個)中排名第 414 位。

累計安裝
207
累計下載
3430
星標
1
全站排名
#3,246
全站前 64% · 「開發程式設計」前 72%
平台累計安裝累計下載星標評論
ClawHub ↗11132841-
SkillHub ↗20734301—

各平台的計數口徑不同,統計時間不一致。

這個技能是做什麼的

僅當標籤頁處於後臺時對新訊息播放提示音,避免打擾前臺使用。功能包括智慧觸發(標籤頁隱藏才響)、0-100% 音量調節、5 檔音效強度(level1 極輕 9.5KB 到 level5 極響 63KB,預設 level3)、自定義音效(MP3/WAV/OGG/WebM)、一鍵開關、localStorage 持久化設定、移動端優雅降級、遵循瀏覽器自動播放策略、3 秒冷卻防轟炸與可選除錯日誌。整合方式:把 client 下的 howler.min.js、notification.js 與 sounds 目錄拷入 webchat 目錄,在 </body> 前引入指令碼並 new WebchatNotifications({soundPath}) 初始化,隨後在訊息事件裡呼叫 notifier.notify();API 含 init/notify(僅標籤頁隱藏時觸發)/test(無視標籤頁狀態試聽)/setEnabled/setVolume/setSound/getSettings。瀏覽器相容:Chrome 92+、Firefox 90+、Safari 15+、Edge 92+ 完整支援,移動端有限支援(iOS 每次播放需使用者手勢),官方稱覆蓋約 92% 使用者(Web Audio API 支援口徑)。體積與效能:打包約 122KB、播放期記憶體約 2MB、CPU 開銷可忽略、一次下載快取使用;安全面為無外部請求、僅用 localStorage、無追蹤、無需特殊許可權。

資料釋出於 2026-10-27

可以用來做什麼

  • 給網頁聊天加後臺標籤頁提示音
  • 按事件型別切換不同音效強度
  • 本地試聽與音量除錯

什麼時候用

  • 網頁聊天需要在標籤頁後臺時有聲音提醒時

示例提示詞

以下是根據技能文件生成的示例,不代表實際執行結果。

給 webchat 裝上後臺訊息提示音
把 @提及 的提示音換成最響的 level5

月度資料趨勢

累計下載3430
2360293535092026-03 · 累計下載 24392026-05 · 累計下載 28432026-06 · 累計下載 29592026-07 · 累計下載 31482026-08 · 累計下載 32172026-09 · 累計下載 343026-0326-09
星標1
0122026-03 · 星標 12026-05 · 星標 12026-06 · 星標 12026-07 · 星標 12026-08 · 星標 12026-09 · 星標 126-0326-09

2026-09 起統計方法調整:同名技能按作者分別統計,並覆蓋全部技能。圖中虛線為調整前的月份,與之後的資料不直接比較,也不計算跨越調整的增長。

月份累計下載環比星標
2026-093430—1
2026-083217+2.2%1
2026-073148+6.4%1
2026-062959+4.1%1
2026-052843—1
2026-032439—1

SKILL.md 原文

以下是作者釋出的原始檔案,按純文字顯示,本站未做修改或稽核;其中的連結不可點選,命令請核實後再執行。抓取於 2026-10-23。

8.0 KB · ClawHub v1.2.0
---
name: webchat-audio-notifications
description: Add browser audio notifications to Moltbot/Clawdbot webchat with 5 intensity levels - from whisper to impossible-to-miss (only when tab is backgrounded).
version: 1.1.0
author: brokemac79
repository: https://github.com/brokemac79/webchat-audio-notifications
homepage: https://github.com/brokemac79/webchat-audio-notifications
tags:
  - webchat
  - notifications
展開全部(共 312 行)
  - audio
  - ux
  - browser
  - howler
metadata:
  clawdbot:
    emoji: 🔔
    compatibility:
      minVersion: "2026.1.0"
      browsers:
        - Chrome 92+
        - Firefox 90+
        - Safari 15+
        - Edge 92+
    dependencies:
      - howler.js (included)
    files:
      - client/howler.min.js
      - client/notification.js
      - client/sounds/notification.mp3
      - client/sounds/alert.mp3
    install:
      - kind: manual
        label: Install webchat audio notifications
        instructions: |
          1. Copy files to your webchat directory:
             - client/howler.min.js → /webchat/js/
             - client/notification.js → /webchat/js/
             - client/sounds/ → /webchat/sounds/
          
          2. Add to your webchat HTML before closing </body>:
          
          ```html
          <script src="/js/howler.min.js"></script>
          <script src="/js/notification.js"></script>
          <script>
            const notifier = new WebchatNotifications({
              soundPath: '/sounds/notification'
            });
            notifier.init();
          </script>
          ```
          
          3. Hook into message events:
          
          ```javascript
          socket.on('message', () => {
            if (notifier) notifier.notify();
          });
          ```
          
          4. Test by switching tabs and triggering a message
          
          See docs/integration.md for full guide.
---

# 🔔 Webchat Audio Notifications

Browser audio notifications for Moltbot/Clawdbot webchat. Plays a notification sound when new messages arrive - but only when the tab is in the background.

## Features

- 🔔 **Smart notifications** - Only plays when tab is hidden
- 🎚️ **Volume control** - Adjustable 0-100%
- 🎵 **5 intensity levels** - Whisper (1) to impossible-to-miss (5)
- 📁 **Custom sounds** - Upload your own (MP3, WAV, OGG, WebM)
- 🔕 **Easy toggle** - Enable/disable with one click
- 💾 **Persistent settings** - Preferences saved in localStorage
- 📱 **Mobile-friendly** - Graceful degradation on mobile
- 🚫 **Autoplay handling** - Respects browser policies
- ⏱️ **Cooldown** - Prevents spam (3s between alerts)
- 🐞 **Debug mode** - Optional logging

## Quick Start

### Test the POC

```bash
cd examples
python3 -m http.server 8080
# Open http://localhost:8080/test.html
```

**Test steps:**
1. Switch to another tab
2. Click "Trigger Notification"
3. Hear the sound! 🔊

### Basic Integration

```javascript
// Initialize
const notifier = new WebchatNotifications({
  soundPath: './sounds',
  soundName: 'level3',  // Medium intensity (default)
  defaultVolume: 0.7
});

await notifier.init();

// Trigger on new message
socket.on('message', () => notifier.notify());

// Use different levels for different events
socket.on('mention', () => {
  notifier.setSound('level5');  // Loudest for mentions
  notifier.notify();
});
```

## API

### Constructor Options

```javascript
new WebchatNotifications({
  soundPath: './sounds',               // Path to sounds directory
  soundName: 'level3',                 // level1 (whisper) to level5 (very loud)
  defaultVolume: 0.7,                  // 0.0 to 1.0
  cooldownMs: 3000,                    // Min time between alerts
  enableButton: true,                  // Show enable prompt
  debug: false                         // Console logging
});
```

**Intensity Levels:**
- `level1` - Whisper (9.5KB) - Most subtle
- `level2` - Soft (12KB) - Gentle
- `level3` - Medium (13KB) - Default
- `level4` - Loud (43KB) - Attention-getting
- `level5` - Very Loud (63KB) - Impossible to miss

### Methods

- `init()` - Initialize (call after Howler loads)
- `notify(eventType?)` - Trigger notification (only if tab hidden)
- `test()` - Play sound immediately (ignore tab state)
- `setEnabled(bool)` - Enable/disable notifications
- `setVolume(0-1)` - Set volume
- `setSound(level)` - Change intensity ('level1' through 'level5')
- `getSettings()` - Get current settings

## Browser Compatibility

| Browser | Version | Support |
|---------|---------|---------|
| Chrome | 92+ | ✅ Full |
| Firefox | 90+ | ✅ Full |
| Safari | 15+ | ✅ Full |
| Mobile | Latest | ⚠️ Limited |

**Overall:** 92% of users (Web Audio API support)

## File Structure

```
webchat-audio-notifications/
├── client/
│   ├── notification.js       # Main class (10KB)
│   ├── howler.min.js         # Audio library (36KB)
│   └── sounds/
│       ├── level1.mp3        # Whisper (9.5KB)
│       ├── level2.mp3        # Soft (12KB)
│       ├── level3.mp3        # Medium (13KB, default)
│       ├── level4.mp3        # Loud (43KB)
│       └── level5.mp3        # Very Loud (63KB)
├── examples/
│   └── test.html            # Standalone test with all levels
├── docs/
│   └── integration.md       # Integration guide
└── README.md                # Full documentation
```

## Integration Guide

See `docs/integration.md` for:
- Step-by-step setup
- Moltbot-specific hooks
- React/Vue examples
- Common patterns (@mentions, DND, badges)
- Testing checklist

## Configuration Examples

### Simple

```javascript
const notifier = new WebchatNotifications();
await notifier.init();
notifier.notify();
```

### Advanced

```javascript
const notifier = new WebchatNotifications({
  soundPath: '/assets/sounds',
  soundName: 'level2',  // Start with soft
  defaultVolume: 0.8,
  cooldownMs: 5000,
  debug: true
});

await notifier.init();

// Regular messages = soft
socket.on('message', () => {
  notifier.setSound('level2');
  notifier.notify();
});

// Mentions = very loud
socket.on('mention', () => {
  notifier.setSound('level5');
  notifier.notify();
});

// DMs = loud
socket.on('dm', () => {
  notifier.setSound('level4');
  notifier.notify();
});
```

### With UI Controls

```html
<input type="range" min="0" max="100" 
       onchange="notifier.setVolume(this.value / 100)">
<button onclick="notifier.test()">Test 🔊</button>
```

## Troubleshooting

**No sound?**
- Click page first (autoplay restriction)
- Check tab is actually hidden
- Verify volume > 0
- Check console for errors

**Sound plays when tab active?**
- Enable debug mode
- Check for "Tab is visible, skipping" message
- Report as bug if missing

**Mobile not working?**
- iOS requires user gesture per play
- Consider visual fallback (flashing favicon)

## Performance

- **Bundle:** ~122KB total (minified)
- **Memory:** ~2MB during playback
- **CPU:** Negligible (browser-native)
- **Network:** One-time download, cached

## Security

- ✅ No external requests
- ✅ localStorage only
- ✅ No tracking
- ✅ No special permissions

## License

MIT License

## Credits

- **Audio library:** [Howler.js](https://howlerjs.com/) (MIT)
- **Sounds:** [Mixkit.co](https://mixkit.co/) (Royalty-free)
- **Author:** @brokemac79
- **For:** [Moltbot/Clawdbot](https://github.com/moltbot/moltbot) community

## Contributing

1. Test with `examples/test.html`
2. Enable debug mode
3. Report issues with browser + console output

## Roadmap

- [ ] WebM format (smaller files)
- [ ] Per-event sounds (mention, DM, etc.)
- [ ] Visual fallback (favicon flash)
- [ ] System notifications API
- [ ] Settings UI component
- [ ] Do Not Disturb mode

---

**Status:** ✅ v1.1.0 Complete - 5 Intensity Levels  
**Tested:** Chrome, Firefox, Safari  
**Ready for:** Production use & ClawdHub publishing

## Links

- 📖 [README](./README.md) - Full documentation
- 🔧 [Integration Guide](./docs/integration.md) - Setup instructions
- 🧪 [Test Page](./examples/test.html) - Try it yourself
- 💬 [Discord Thread](https://discord.com/channels/1456350064065904867/1466181146374307881) - Community discussion

「開發程式設計」分類下的熱門技能

資料月份:2026-09 · 下載/星標/安裝數聚合自公開技能註冊庫(ClawHub、SkillHub),按月更新。口徑說明見資料方法。