<commit_before>---
title: "Asterisk Channel Variables Guide - Asterisk Channel Library"
shortTitle: "Channel Variables"
date: 2015-04-20
template: article.jade
showInMenu: "true"
menuOrder: 20
meta:
    keywords: "respoke, asterisk, chan_respoke"
    description: "Learn how to use respoke asterisk channel variables."
---

###Asterisk Channel Library
# Asterisk Channel Variables 

## Overview

Your users need an access token to connect to Respoke. The access token provides both authentication of who they are and authorization of what they are allowed to do. 

Development mode makes getting started easy, but is inherently insecure. In production, you need a server to verify users and request a token on their behalf and connect to Respoke using this token. This gives you fine-grained control over users and permissions.

When you request a token, you need to provide:

- `endpointId`: Usually your user's username
- `appId`: The App ID for your App
- `appSecret`: The App Secret for your App
- `roleId`: A set of permissions you create in the Respoke Dashboard for your App
- `ttl`: The number of seconds the token is valid

The first step in this process is disabling Development Mode for your App.

## Creating App Roles

Next, you need to create a Role to specify what Respoke operations the `endpointId` can do.

1. Go to your App in the [Respoke Dashboard](https://portal.respoke.io/#/apps/).

2. Selet your App.

3. Validate development mode is disabled.

4. Create new role, give the role a name and choose it's permissions.

5. Take note of your appId, appSecret and new roleId.

Respoke and your App are now set up for authentication. It's time to write some code.

## Authenticating With Respoke

First, request a `token` from your server.

    // Create an instance of the Respoke client
    var client = respoke.createClient();

    // Create HTTP POST request to authentication server
    (function connect() {
      $.ajax({
          method: "POST",
          url: "your/server/api/tokens",
          data: {
              endpointId: "<EMAIL>"
          },
          success: function(response) {
              var token = response.token;
        
              client.connect({
                  token: token          
              });
          }
      })
    })();
    
    // "connect" event fired after successful connection to Respoke
    client.listen("connect", function(e) {
        console.log("Connected to Respoke!", e);
    });
    

Then your server will request this `token` from Respoke.

{example: endpoint-authentication}

Use this `token` to connect your client to Respoke.

Additionally, you'll need to listen to the `disconnect` event. Then request a new `token` from your server and use this new `token` to re-connect your client to Respoke.

    client.listen("disconnect", function (evt) {
        // Reconnect to Respoke
        connect();
    });
<commit_msg>Added Asterisk Channel Library Channel Variables<commit_after>---
title: "Asterisk Channel Variables Guide - Asterisk Channel Library"
shortTitle: "Channel Variables"
date: 2015-04-20
template: article.jade
showInMenu: "true"
menuOrder: 20
meta:
    keywords: "respoke, asterisk, chan_respoke"
    description: "Learn how to use respoke asterisk channel variables."
---

###Asterisk Channel Library
# Asterisk Channel Variables 

## Overview

You can access Respoke session variables in your dialplan. First, validate you have asterisk and [chan_respoke compiled and running](/client/asterisk/getting-started.html).

## Asterisk Channel Variables

You can use the following Respoke session information inside the asterisk channel:

- respoke_session_local
- respoke_session_local_type
- respoke_session_local_connection
- respoke_session_remote
- respoke_session_remote_type
- respoke_session_remote_connection
- respoke_session_remote_appid
- respoke_session_id

## The Dialplan

Here is a dialplan showing how to pass the "respoke_session_remote" inside an asterisk channel variable:

    exten => your_respoke_endpoint,1,Answer()
    same => n,NoOp(RESPOKE METADATA: ${respoke_session_remote})
    same => n,Ringing
    same => n,Wait(8)
    same => n,Playback(welcome)
    same => n,SayAlpha(${respoke_session_remote})
    same => n,Dial(SIP/300)
    same => n,Hangup()
    
Here, the "respoke_session_remote" information is played back to the caller using the Asterisk application SayAlpha. The "respoke_session_remote" is the endpointId of the remote caller. This value can be a username, orderId or anything that could uniquely identify the caller.
{'fraction_non_alphanumeric': 0.07842278203723987, 'fraction_numerical': 0.0065717415115005475, 'mean_word_length': 3.5387673956262424, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 12, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6807430', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1229, 'n_words': 529}