This is a Next.js project bootstrapped with create-next-app
.
This App is built with node v18. Hence, this project needs node18, which can be installed with nvm.
nvm use
First, install the project dependencies.
yarn sample-app:install
For local development, run the development server.
yarn sample-app:dev
Open http://localhost:3000 with your browser to see the result.
For building the App for deployment,
yarn sample-app:build
Start the App with below command
yarn sample-app:start
Open http://localhost:3000 in the browser for the App.
- Create a non-flex account in the Twilio stage or production.
- Open the TaskRouter sample app on
http://localhost:3000
and provide the required account details - Next, click
Get New Token.
This step will initialize the Worker and prepare the Worker to accept the Task. - Create a new task and make the Worker Available in the Twilio console UI.
https://console.stage.twilio.com/us1/service/taskrouter/${YOUR_TASKROUTER_WORKSPACE_ID}/taskrouter-workspace-tasks
andhttps://console.stage.twilio.com/us1/service/taskrouter/${YOUR_TASKROUTER_WORKSPACE_ID}/taskrouter-workspace-workers
- TaskRouter Sample App will display the allocated reservation details to the Worker and provide the option to accept or reject the Task.
Detailed steps are documented below.
2. Steps to create a TaskRouter Workspace and to create a Task in staging (same steps would work for production)
- Login to https://www.stage.twilio.com/
- Click on Create new account
- Provide the name to the account
- Provide a phone number where verification code would be sent
- Select
Other Twilio product
and not Flex-based product. (Note: Flex account doesn't allow the create more than one workspace) - Select
Other
for what you plan to build - Select
With No code at all
and then create. Copy theAccount SID
. - Go to
Account
>API Keys & Tokens
and provide the code received via emailhttps://console.stage.twilio.com/us1/account/keys-credentials/api-keys
. - Click
Create API Key,
give a Friendly Name, and click Create. - Copy API SID and secret, accept the copied checkbox, and click
Done
. Copy the API SID asSigningKey SID
and the secret asSigningKey Secret
. - Once the account is created, select
TaskRouter
underExplore Products
and pint it. - Now, go under TaskRouter > Workspace
https://console.stage.twilio.com/us1/develop/taskrouter/workspaces
and clickcreate new workspace
. Copy theWorkspace SID
. - Give a name to the workspace and create with default settings.
- Now, create a worker after going inside your newly created workspace
https://console.stage.twilio.com/us1/service/taskrouter/${YOUR_TASKROUTER_WORKSPACE_ID}/taskrouter-workspace-workers
. - Click
Create new worker
and give a name, sayYour_Worker_Name
, Activity toAvailable
and Attributes to{"skills": "support"}.
Click onSave
. Copy theWorker SID
andYou_Worker_Name
asIdentity
. - Go to Tasks under TaskRouter
https://console.stage.twilio.com/us1/service/taskrouter/${YOUR_TASKROUTER_WORKSPACE_ID}/taskrouter-workspace-tasks
. - Click
Create new Task
, Workflow toDefault Fifo Workflow
, Task Channel toVoice,
and then Create Task.
- Run the project after installing
pnpm install && pnpm dev
- This will start the application at port 3000
http://localhost:3000
- Provide the
Account SID
from the above steps. - Provide
SigningKey SID
andSigningKey Secret
from the above steps. - Provide
Workspace SID
from the above steps. This could be found at this linkhttps://console.stage.twilio.com/us1/develop/taskrouter/workspaces
. - Provide
Worker SID
from above the above steps. This Could be found at this linkhttps://console.stage.twilio.com/us1/service/taskrouter/${YOUR_TASKROUTER_WORKSPACE_ID}/taskrouter-workspace-workers
. - Provide Identity from the above steps.
https://console.stage.twilio.com/us1/service/taskrouter/${YOUR_TASKROUTER_WORKSPACE_ID}/taskrouter-workspace-workers
. - Provide environment as
stage.
- Click on
Get New Token.
This will generate and initialize a new token for the TaskRouter worker. Check the Logs in the UI for the initialization success log message. - Go to console.stage.twilio.com and create a new Task following above steps. This could be found at this link
https://console.stage.twilio.com/us1/service/taskrouter/${YOUR_TASKROUTER_WORKSPACE_ID}/taskrouter-workspace-tasks
. - Make sure the Worker is in an
Available
state to be able to assign the Task. - Sample App UI will show a new Reservation, and both the
Accept
andReject
button is enabled to act on the Task for the given work.