Q:

Adding duration for custom toast message in Lightning

Able to display Toast message in Lightning. But I need to set duration for lightning toast messages how can I do it. I need to display toast message for few seconds in screen..now what's happening is it will stay in screen forever..after showing msg it should appear .. for below line of code.
I have tried  like this:
 showNotification : function(component,variant,title,messageBody,mode){
    component.find('message').showToast({
        "variant": variant,
        "title": title,
        "message": messageBody,
         duration:' 5000',
        "mode": mode
    });

Components:
  <lightning:notificationsLibrary aura:id="message"/>

Js side:
  if(component.get('v.phoneQSelected') === '--None--'){
        helper.showNotification(component,"Error","Missing Value","What phone Q did the call originate on?","sticky");
        return;
    }

 showNotification : function(component,variant,title,messageBody,mode){
    component.find('message').showToast({
        "variant": variant,
        "title": title,
        "message": messageBody,

        "mode": mode
    });

A:

For now, the only way to specify a duration is force:showToast.
$A.get("e.force:showToast")
    .setParams({duration: 5000, ... })
    .fire();

The lightning:notificationsLibrary is the preferred mechanism, but does not allow you to specify anything other than until dismissed, dismissed or 3 seconds, or 3 seconds.

