twilio-api


Facing issue with Twilio Taskrouter sample client


I have developed an application (Client and Server) for Taskrouter as mentioned in https://www.twilio.com/docs/quickstart/java/taskrouter/agent-ui-add-project link.
After opening a http://myserver:8080/twilio/taskrouter/agents?WorkerSid=WKc56xxxxxxxx I get below error.
VM68:1 Uncaught SyntaxError: Unexpected token , in JSON at position 766(…)
decodePayload # taskrouter.min.js:2
(anonymous function) # taskrouter.min.js:2
decode # taskrouter.min.js:2
objectize # taskrouter.min.js:2
(anonymous function) # taskrouter.min.js:2
WorkerClient # taskrouter.min.js:1
window.onload # VM64 agents?WorkerSid=WKcXXXXX…:112
After debugging it, I found there is an error in JSON format in taskrouter.min.js where the JSON get assigned to decoded_payload variable.
{
"iss":"ACa0cxxxxxxxx",
"exp":1479363953,
"workspace_sid":"WSb84xxxxxxxx",
"policies":[
{
"url":"https://taskrouter.twilio.com/v1/Workspaces/WSb84xxxxxxxx/Activities",
"method":"GET",
"allow":true
},{
"url":"https://taskrouter.twilio.com/v1/Workspaces/WSb84xxxxxxxx/Tasks/**",
"method":"GET",
"allow":true
},
{
"url":"https://taskrouter.twilio.com/v1/Workspaces/WSb84xxxxxxxx/Workers/WKc56xxxxxxxx/Reservations/**",
"method":"GET",
"allow":true
},
{
"url":"https://taskrouter.twilio.com/v1/Workspaces/WSb84xxxxxxxx/Workers/WKc56xxxxxxxx",
"method":"POST",
"post_filter",
"ActivitySid":{
"required":true
},
"allow":true
},
{
"url":"https://taskrouter.twilio.com/v1/Workspaces/WKc56xxxxxxxx/Tasks/**",
"method":"POST",
"allow":true
},
{
"url":"https://taskrouter.twilio.com/v1/Workspaces/WSb84xxxxxxxx/Workers/WKc56xxxxxxxx/Reservations/**",
"method":"POST",
"allow":true
},
{
"url":"https://event-bridge.twilio.com/v1/wschannels/ACa0cxxxxxxxx/WKc56xxxxxxxx",
"method":"GET",
"allow":true
},
{
"url":"https://event-bridge.twilio.com/v1/wschannels/ACa0cxxxxxxxx/WKc56xxxxxxxx",
"method":"POST",
"allow":true
}
],
"account_sid":"ACa0cxxxxxxxx",
"version":"v1"
}
The server generate wrong JSON for postFilter for ActivitySid. Below is the server side code snippet.
public void generateAgentView(final HttpServletRequest request, final HttpServletResponse response)
throws ServletException, IOException {
final String workerSid = request.getParameter("WorkerSid");
List<Policy> policies = PolicyUtils.defaultWorkerPolicies(workspaceSid, workerSid);
Map<String, FilterRequirement> activityUpdateFilter = new HashMap<>();
activityUpdateFilter.put("ActivitySid", FilterRequirement.REQUIRED);
Policy allowActivityUpdates = new Policy.Builder()
.url(UrlUtils.worker(workspaceSid, workerSid))
.method(HttpMethod.POST)
.postFilter(activityUpdateFilter).build();
Policy allowTasksUpdate = new Policy.Builder()
.url(UrlUtils.allTasks(workerSid))
.method(HttpMethod.POST)
.build();
Policy allowReservationUpdate = new Policy.Builder()
.url(UrlUtils.allReservations(workspaceSid, workerSid))
.method(HttpMethod.POST)
.build();
policies.add(allowActivityUpdates);
policies.add(allowTasksUpdate);
policies.add(allowReservationUpdate);
TaskRouterCapability.Builder capabilityBuilder =
new TaskRouterCapability.Builder(accountSid, authToken, workspaceSid, workerSid)
.policies(policies);
String token = capabilityBuilder.build().toJwt();
System.out.println(token);
// By default, tokens are good for one hour.
// Override this default timeout by specifiying a new value (in seconds).
// For example, to generate a token good for 8 hours:
token = capabilityBuilder.build().toJwt();
// Forward the token information to a JSP view
response.setContentType("text/html");
request.setAttribute("worker_token", token);
final RequestDispatcher view = request.getServletContext().getRequestDispatcher("/agent.jsp");
view.forward(request, response);
}
If I do not add the postFilter(activityUpdateFilter) to allowActivityUpdates then I get another below error.
taskrouter.min.js:1 Uncaught Error: Missing minimum payload values. Check for existence of account_sid,channel or workspace_sid in the token(…)
EventBridgeClient # taskrouter.min.js:1
TaskRouterEventBridgeClient # taskrouter.min.js:1
WorkerClient # taskrouter.min.js:1
window.onload # agents?WorkerSid=WKcXXXXX…:112
Could you help me to resolve these issues?

Related Links

Place Outbound Twilio Call and Respond to User Input
Twilio Recording Ongoing call
TaskRouter Redirect to Client Browser in Java
Facing issue with Twilio Taskrouter sample client

Categories

HOME
ionic-framework
image
deezer
tizen
plone
angular-material
smarty
syntax
kalman-filter
jsrender
fsm
webpack-2
convolution
slurm
spring-tool-suite
remote-access
messages
msp430
quartz-scheduler
pc
undefined
object-detection
emgucv
tdd
qhull
traffic
phpfox
typo3-6.2.x
saas
dbclient
file-rename
http-status-code-503
noraui
mozilla
geopositioning
android-browser
android-fingerprint-api
awt
particles.js
optix
ensembles
eclipse-scout
texmaker
nand2tetris
azure-application-gateway
react-scripts
hendrix
pebble-watch
veracode
fancybox-2
knockout-components
composite-key
libusb-win32
python-cryptography
color-profile
nested-sets
static-ip-address
color-picker
heidisql
azure-virtual-network
dstu2-fhir
py2app
websitepanel
ubuntu-10.04
actionbardrawertoggle
skype4py
suffix-tree
thredds
qdialog
atk4
sframe
sysinternals
unity5.2.3
e10s
python-green
dia
block-device
javafx-webengine
heisenbug
doskey
cloud-connect
centos5
c18
ccss
jsctypes
inbox
runtime.exec
dataservice
orchardcms-1.7
pygit2
flashvars
drools-planner
robotics-studio
clipper
angularjs-controller
chuck
armcc
gwt-ext
doh
heartbeat
servicehost
digest-authentication
coda-slider
.nettiers
dentrix
putchar
spec#

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile