The API does not provide any method to obtain information about the npc you are in a dialogue with at any given moment. There are 3 methods you can use to determine the npc although all of them have exceptions.
1. Get the npc you are interacting with (easiest)
myPlayer().getInteracting().getId();
Works when you click on the npc and your player starts moving towards the npc as well as for 1 tick after each response from the npc. You could use this to determine the id before the actual dialogue.
2. Find the npc that is interacting with you (least reliable)
npcs.getAll().stream().filter(n -> n.getInteracting() == myPlayer()).findFirst().get().getId();
The npc should be interacting with you for 1 tick after each response from you. The main issue here is that other people might attempt to start dialogues with same npc leading to undefined behaviour.
3. Extract npc name from dialogue widget and then search for the npc (most reliable)
npcs.getAll().stream().filter(n -> n.getName().equals(widgets.get(WIDGET_COORDINATES).getMessage())).findFirst().get().getId();
Where WIDGET_COORDINATES represents the ids of the npc name widget on your dialogue interface. The only drawback of this method is that you can only obtain the id of the npc once they are the ones talking.
You can also filter the npcs using the API Filter class if you don't like lambda expressions:
npcs.closest(new Filter<NPC>() {
@Override
public boolean match(NPC n) {
return n.getInteracting() == myPlayer();
}
}).getId();
That's pretty much all you can do with the API right now, the main issue being that npc interaction is not a continuous thing, at least not for dialogues. It is continuous for instance if you are safespotting an npc and that npc keeps trying to reach your player but they can't. In this case, that npc will be interacting with your player. But anyway, there is absolutely no need for the npc id you are in dialogue with so we don't really have a method that provides that 100% accurate result.