There are a few separate issues you need to deal with here.
The first is whether you still want to be with your boyfriend. After a number of years it does take effort to keep relationships fun and it's natural for the initial excitement to become a more comfortable companionship. This is, however, a different thing to a relationship having run its course for you and you no longer wanting to be in it. If you don't want to be with him anymore then you owe it to your boyfriend to break up with him rather than stay together out of habit or a sense of obligation.
Second, if you are staying with your boyfriend then you need to stop texting his friend. You clearly realise that the two of you are flirting and we all know that just because you haven't kissed or physically cheated that this doesn't mean what you are doing is ok. How would you feel if your boyfriend had been exchanging the same messages and pictures with one of your friends?
Third, if you do end things with your current boyfriend and you like his friend, would it really be wise to pursue something? It would be hurtful to your boyfriend (ex as he would be in this scenario) and do you really want a relationship with a man who is so comfortable in betraying his friends? Can you cope with the way your current boyfriend would react? Can you deal with the way friends and family might react? If you really would feel ok about all of that, then that's fine for you but don't underestimate those issues. Most people won't see you in a good light if you go down this road and you need to be prepared to be seen as the bad guy for getting with your boyfriend's friend even if you ended things first.
Ultimately, only you know what you want and you have to make these choices for yourself but unless you want to get yourself into a horrible mess then the one really clear thing is that you have to make a choice and stick to it.