Skip to content

Conversation

@konard
Copy link
Owner

@konard konard commented Oct 17, 2025

Summary

This PR implements a solution for issue #32 by adding an automatic friend request feature when receiving messages from non-friends.

Changes

  • New Trigger: SendFriendRequestToNonFriend trigger in triggers/send-friend-request-to-non-friend.js

    • Automatically detects when a message is received from a non-friend
    • Sends a friend request to that VK user via the VK API
    • Only processes incoming messages from users (not groups/chats or outgoing messages)
  • Smart Duplicate Prevention:

    • Tracks trigger execution per user with a 7-day cooldown period
    • Prevents sending duplicate friend requests to the same user within 7 days
  • Robust Error Handling:

    • Handles VK API error code 174 (already friend or request pending)
    • Handles VK API error code 177 (user not found or deactivated)
    • Handles VK API error code 242 (friend count limit of 10,000 exceeded)
    • Handles VK API error code 29 (rate limit reached)
    • Handles VK API error code 15 (access denied due to privacy settings)
  • Enabled by Default: The trigger is enabled in index.js and will run automatically on incoming messages

  • Comprehensive Tests:

    • Added unit tests in __tests__/triggers/send-friend-request-to-non-friend.js
    • 12 test cases covering all scenarios (condition checks, error handling, etc.)
    • All tests passing ✅

Implementation Details

The trigger follows the established patterns in the codebase:

  • Uses the executeTrigger utility from utils.js
  • Leverages the getAllFriends function from friends-cache.js to check friend status
  • Uses VK API's friends.add method to send friend requests
  • Implements proper error handling for all known VK API error codes

Testing

Run tests with:

npm test -- __tests__/triggers/send-friend-request-to-non-friend.js

All 12 tests pass successfully.

Fixes #32

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: undefined
@konard konard self-assigned this Oct 17, 2025
Implements a new trigger that automatically sends friend requests to VK users who send messages but are not currently friends. The trigger includes:

- SendFriendRequestToNonFriend trigger that checks if message sender is a friend
- If not a friend, sends a friend request via VK API
- Prevents duplicate requests by tracking trigger execution per user (7-day cooldown)
- Comprehensive error handling for VK API error codes (174, 177, 242, 29, 15)
- Only processes incoming messages from users (not groups/chats)
- Includes unit tests with 12 test cases covering all scenarios

Fixes #32

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] On message from a non-friend, send a friend request to that VK user Add trigger to send friend requests to non-friends Oct 17, 2025
@konard konard marked this pull request as ready for review October 17, 2025 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

On message from a non-friend, send a friend request to that VK user

1 participant