I think you can check that the NPC is interacting with you, and that it has mentioned your player's name in the last x seconds, and has a certain action, like Dismiss.
Maybe something like this (note completely untested):
Optional<NPC> randomNPCOpt = getNpcs().getAll().stream().filter(npc ->
npc.getActions() != null &&
Arrays.asList(npc.getActions()).contains("Dismiss") && // NOT SURE WHAT THE ACTION IS HERE
npc.isInteracting(myPlayer()) &&
npc.hasMentionedPhrase(myPlayer().getName(), 30000) && // check the NPC is saying our name
npc.getModel() != null
).findAny();
if (randomNPCOpt.isPresent()) {
NPC randomNPC = randomNPCOpt.get();
switch (randomNPC.getName()) {
case "Genie":
handleGenie();
break;
default:
randomNPC.interact("Dismiss"); // NOT SURE WHAT THE ACTION IS HERE
break;
}
}