Twilio REST API to Flex - twilio

Looking for a little guidance here. The docs don't really cover this use case, so can someone please let me know if 1) this is possible, and 2) how to accomplish it?
Sequence:
REST Api to create a task
|
That task ends up as an incoming SMS in Twilio Flex
|
A worker accepts/responds via the Flex console
|
that message is sent to the user via text (SMS)
I've been testing in postman, and got it to the point where I can create a task, and it shows up in Flex, but it comes in as a default task with no sms component.
The docs are pretty thin regarding what the task creation fields can be, let alone what their values need to be.
Attributes = { "type" : "web", "to": "2024105613", "from" : "+14086871234", "queue" : "Everyone", "task-reason" : "service_request", "body" : "joel test" }
Please let me know if the use case / sequence I'm attempting is possible, and if so, do you have any pointers on what I'm doing wrong?
Thanks in advance!
More info/clarification:
What I'm hoping to do is have the worker see the incoming help request/task (that was sent in via the REST API) in Flex, and then respond in flex to the user which shows up on the user's device as a text message.
Right now, I can get the task to show up in flex, and I see the phone number that it "came" from, but I struggling with how I can have the worker respond via sms from the Flex portal.

Related

For the Twilio Action - SendMessage, Where can i find the `conversationSid` ? This is to respond to an existing webchat

I have a basic twilio-flex 2.0 setup in my local. I have a plugin which basically renders a button. I am responding to a "customer" message which pops up in my list. I have a the button's "onClick" implemented to send a pretyped message , I am unable to find the conversationSid, that I need to plug into this below.
Actions.invokeAction('SendMessage',
{
body: "TBD",
conversationSid: "Where can i find this?"
})})
For the sake of testing, I was able to find the conversationSid in the browser console and plugged it in there and message is sent.
The documentation shows that the conversationSid is optional, but without it, nothing is sent.
Any help or direction would be much appreciated ?
Thanks to #csevero , i was able to figure out the way
conversationSid: this.manager.store.getState().flex.chat.messageList.activeChatChannel

Send message to self-Chat in Microsoft Teams using Graph API

I'm trying to send a message to my self-Chat in Microsoft Teams through a Graph API call but can't find the ID of this specific chat. For the record, this type of chat was introduced to Teams in June, 2022.
By reading the Graph API documentation, it's possible to list all chats available for a specific user using the following API call (in this case, myself):
[GET] https://graph.microsoft.com/beta/me/chats/
Yet, I can't seem to find my self-chat in there. The chat itself is already created since I wrote messages in it but it doesn't appear in the call response.
I've tried to filter the results by most recent results, by filtering on my own name or by filtering by ChatType, but it was still missing.
Is anyone aware of a way to get the ID of a user self-chat in Microsoft Teams?
Thanks!
Self chat is a special kind, You can use this endpoint to communicate with it:
https://graph.microsoft.com/v1.0/me/chats/48:notes/messages
Hope that helps :)
Answering harrywyn's question regarding the pop up notification, you can set it as unread the same as any chat like this:
EndPoint = f'https://graph.microsoft.com/v1.0/chats/48:notes/markChatUnreadForUser'
update_chat = {
"user": {
"id" : uid,
"tenantId": TENANT_ID
}
}
resp = requests.post(EndPoint, headers=headers, verify=False, json=update_chat)

Twilio Target Worker Expression--blocking voice calls while on a text

I've read the documentation here: https://www.twilio.com/docs/taskrouter/multitasking#preventing-a-worker-from-receiving-chat-tasks-if-on-a-voice-task on how to block an agent from getting chats while they are on a voice call, but I want to do the reverse with a twist.
I successfully managed to stop workers from getting a voice call while they have an active chat going using "worker.channel.chat.assigned_tasks == 0" as the Expression. However, it also prevents a second chat, SMS, Facebook, or WhatsApp message coming in even though the worker's capacity is higher than 1.
Would love suggestions on what the expression should be so that the additional SMS or chats can come through up to the worker's capacity but not any voice calls when they have an active chat or SMS going.
The following filter should do the trick. The expression will only apply to voice tasks and the target routes to workers with no assigned chats.
{
"filter_friendly_name": "Do not assign Voice Tasks if assigned Chat",
"expression": "(task_channel_unique_name=='voice')",
"targets": [
{
"queue": <default queue sid>,
"expression": "worker.channel.chat.assigned_tasks == 0"
}
]
},

Taskrouter problem using Laravel. Task not getting created?

I've followed every single step in the Twilio's documentation called Dynamic Call Center with Laravel.
My problem is that a call gets through the IVR, then after choosing a digit, nothing happens.
My guess is that its not creating a task. the code provided in the documentation just generate a task with json but thats it. I check my tasks in Twilio taskrouter console and nothing shows up.
I've provided all credentials, used ngrok, filled in all url callbacks.
public function enqueueCall(Request $request)
{
define('workflowSid', env('TWILIO_WORKFLOW_SID'));
$selectedSkillInstruction = new \StdClass();
$selectedSkillInstruction->selected_skill = $this->_getSelectedSkill($request);
$response = new Twiml();
$enqueue = $response->enqueue(['workflowSid' => workflowSid]);
$enqueue->task(json_encode($selectedSkillInstruction));
return response($response)->header('Content-Type', 'text/xml');
}
I expect a code that actually creates a task, but when I call this api via postman, a task is not created
The above code returns Twilio Markup Language (TwiML) which uses the enqueue verb and a workflowSid attribute. The enqueue verb is used with Programmable Voice. Have you tried associating your application with a Twilio phone number and then calling the Twilio number which should enqueue the call into a task router workflow?
TwiML Voice: Enqueue
https://www.twilio.com/docs/voice/twiml/enqueue#attributes-workflowSid
I have solved my problem. It turned out that everything was in order, the only problem is that I didn't know I need to press # after choosing from the IVR because all the demo I saw from Twilio only press a number and it gets routed.

How do I get twilio 5 digit error code for a failed voice call?

We have a callback url in place that is correctly capturing the failed status of a call.
Our code then fetches from twilio the details of the call by doing the following:
$call = $twilio_client->calls($sid)->fetch();
Within the call details returned there is no 5 digit error code listed, even though the failed status is present.
How do we get the 5 digit error code that caused the failure?
Twilio developer evangelist here.
Thanks to #miknik for the answer, however that is actually a deprecated resource (which is why you can't currently find any documentation on the matter). It's taken me a while to find the answer as I've been chasing down where the notifications have gone.
The Notifications API was deprecated in favour of the Monitor Alerts API. This API can give you all the details about an alert, including the 5 digit code.
The best way to receive these alerts for your application is to set up a webhook in your account console which will send all the parameters about the alert as part of the request.
You can also list your alerts which will allow you to find alerts from a specific resource SID (in your case, a call SID).
Let me know if this helps at all.
Make an authenticated GET request to
/2010-04-01/Accounts/{AccountNumber}/Calls/{CallSid}/Notifications
So in PHP the following will retrieve the notification info for your call
$json = file_get_contents('https://{AccountNumber}:{AuthToken}#api.twilio.com/2010-04-01/Accounts/{AccountNumber}/Calls/{CallSid}/Notifications.json');
Then use this line to get the returned JSON into an associative array
$obj = json_decode($json, true);
Now if all you want is the error code its stored as the following variable
echo $obj[notifications][0][error_code];
However, the full error info is also returned as a URL encoded string. You can access this by first urldecoding it, and then parsing the query string into an array with the following line
parse_str(urldecode($obj[notifications][0][message_text]), $output);
And you can now access the variables within like this
echo $output[Msg]; // Error text for failure eg invalid phone number
echo $output[phonenumber]; // Phone number for failed call
echo $output[ErrorCode]; // 5 digit error code
echo $output[LogLevel];` // Log level of error eg WARN
As far as I know this is not implemented in the PHP helper library, so you have to code for it manually

Resources