Sell some tokens when 'buying' on Uniswap

Hello
I just want a (hopefully)simple functionality in my ERC20 token, that it sells some proportion of the tokens that an address is buying on Uniswap. I realize that for the same, contract itself would need some tokens to sell, it also needs to identify the "buying" action, and not sell on other actions like, sell and liquidity update.
From my knowledge and some research, I could implement it so that, it identifies liquidity updates and token sell. But it is unable to sell tokens when buying, neither from Uniswap's interface, nor Etherscan's 'read contract' part.
Is there anything specific I need to know, about the flow of functions in Uniswap or something else, as I am sure, it could be a direct thing.

Following is my implementation so far

function _transferFrom( sender, recipient, amount returns (bool) {
        bool selling = (msg.sender == address(router) &&
            recipient == address(pair));
        bool removingLiquidity = (msg.sender == address(router) && sender == address(router));
        bool buyingToken = msg.sender == address(pair) &&
            sender == address(pair); // and recipient is some address of final tokens

        if (buyingToken) {
            _balances[sender] = _balances[sender].sub(
                amount,
                "Insufficient Balance"
            );

            uint256 swapThis = amount.mul(somePercent).div(100);

            _balances[recipient] = _balances[recipient].add(
                amount.sub(swapThis)
            );

            _approve(address(this), address(router), swapThis);

            address[] memory path = new address[](2);
            path[0] = address(this);
            path[1] = router.WETH();

            uint256 previous = address(this).balance;

            router.swapExactTokensForETHSupportingFeeOnTransferTokens(
                amountToSwap,
                0,
                path,
                address(this),
                block.timestamp
            );

            uint256 final balance = address(this).balance.sub(previous);
        } else {
            return _simpleTransfer(sender, recipient, amount);
        }

        emit Transfer(sender, recipient, amount);
        return true;
    }

Any help would be seriously appreciated.
Thanks