How to add variables in *.libraries.yml in drupal 8 I need to convert the below code added in hook_page_attachments()
 and
 add the external js in *.libraries.yml but not sure how to add variables like 
$token and $user->mail in the *.libraries.yml so I can just attach library

   drupal_add_js('http://js.acobot.com/' . check_plain($token) . '.js', 'external');
    $script = 'var _aco = _aco || [];';
    drupal_add_js($script, array('type' =&gt; 'inline', 'scope' =&gt; 'footer'));
    if ($user-&gt;uid) {
      $user_info = "_aco.push(['email', '" . check_plain($user-&gt;mail) . "']);";
      drupal_add_js($user_info, array('type' =&gt; 'inline', 'scope' =&gt; 'footer'));
    }


Add Your Script to a file
In *.libraries.yml, I have added

acobot-initialise:
  version: 1.x
  js:
    js/acobot.js: {}
  dependencies:
    - core/jquery
    - core/drupalSettings


Added that file to the library under   


  $attachments['#attached']['library'][] =
  'acobot/acobot-initialise';


Use drupalSettings to pass data from php to js 

  $attachments['#attached']['drupalSettings']['acobot']['email'] = check_plain($account-&gt;getEmail());


Added script acobot.js as follows


  (function ($, Drupal, drupalSettings) {
  
  'use strict';
  
  Drupal.behaviors.acobot = {
      attach: function (context, settings) {
            var _aco = _aco || [];
            _aco.push(['email', drupalSettings.acobot.email]);
      }   };
  
  })(jQuery, Drupal, drupalSettings);
First add your acobot script inline:

function mymodule_page_attachments(array &amp;$attachments) {
  $attachments['#attached']['html_head'][] = [
    // The data.
    [
      '#type' =&gt; 'html_tag',
      // The HTML tag to add, in this case a  tag.
      '#tag' =&gt; 'script',
      // The value of the HTML tag, here we want to end up with
      // alert("Hello world!");.
      '#value' =&gt; 'alert("Hello world!");',
      // Set attributes like src to load a file.
      '#attributes' =&gt; array('src' =&gt; 'http://js.acobot.com/' . check_plain($token) . '.js'),

    ],
    // A key, to make it possible to recognize this HTML  element when altering.
    'hello-world',
  ];
}


next add your library with *.js file where you can call push method 

cuddly-slider:
  version: 1.x
  js:
    js/cuddly-slider.js: {}
  dependencies:
    - core/jquery
    - core/drupalSettings


and pass user mail to  drupalSettings.

$build['#attached']['drupalSettings']['fluffiness']['cuddlySlider']['foo'] = 'user mail here';


All examples are available here https://www.drupal.org/docs/8/creating-custom-modules/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-module