I have a Dialogflow Bot that is integrated with a Twilio phone number. I am trying to get Twilio to pass the "from" number that initiates an interaction to Dialogflow, so I can later log it in a fulfillment.
I put this in Fulfillment:
function reschedule(agent) {
const OriginalDetectIntentRequest = agent.parameters.OriginalDetectIntentRequest;
then: axios.post('https://sheetdb.io/api/v1/q0te84lfo1aal?sheet=Appointments', {
"data": {
"student": student,
"to_date": to_date,
"from_date": from_date,
"created": new Date(),
"OriginalDetectIntentRequest" : OriginalDetectIntentRequest,
}
});
Everything posts except the OriginalDetectIntentRequest.
Here's the reference: https://cloud.google.com/dialogflow/es/docs/reference/rest/v2/OriginalDetectIntentRequest
Related
Using a Microsoft Teams bot and the graph call create api, I am able to call myself (as operator) and transfer the call to an outbound PTSN number. When the bot calls myself, I can confirm it calls using the specified resource account and the associated phone number. However, when transferring this call to the PTSN number, the receiving PTSN number sees my number instead of the bot's resource account number.
Is there a way to specify which resource account to use when transferring the call to the PTSN number? I have searched the docs, but could not find any solution.
To make it clear:
Bot calls operator using resource account (e.g. +318001234).
Operator takes the call, the bot receives the established state update and starts the transfer to the PTSN number (e.g. +31612345678)
The receiver of the transfer now sees the number of the person being transferred. I would like the receiver to see the number of the bot (+318001234 in this example).
Request payload used to transfer:
{
"transferTarget": {
"endpointType": "default",
"identity": {
"phone": {
"id": [PTSN NUMBER OF RECEIVER]
}
},
},
"transferee": {
"identity": {
"user": {
"id": [ID OF OPERATOR],
"tenantId": [OPERATOR TENANT ID]
}
}
}
}
I am attempting to build out a process that will do the following:
New contact lands in my CRM (Podio)
The CRM is triggered to send a POST containing a custom parameter to Twilio which will then initiate a flow
The Twilio flow will call my cell and prompt me to connect to the new contact
Once I press 1, it will take the custom parameter (new contact's phone number) and connect
me to them.
So far, I have been able to get 1-3 with no problem.
However, according to the the API documentation from Twilio I should be able to pass a 3rd parameter in the JSON body of my HTTP request containing custom "Parameters". When I attempt this the parameters aren't showing in the Twilio studio logs and thus I am unable to connect the call to the new lead.
This is the JSON body I am sending over to my Twilio Flow's API
{
"To": "+1xxxxxxxxx1",
"From": "+1xxxxxxxxx2",
"Parameters": {
"name": "example name",
"prospectphone": "+1xxxxxxxxx3"
}
}
When I view the logs in Twilio this is what I received.
{
"contact": {
"channel": {
"address": "+1xxxxxxxxx2"
}
},
"trigger": {
"request": {
"from": "+1xxxxxxxxx2",
"to": "+1xxxxxxxxx1",
"parameters": {}
}
},
"widgets": {},
"flow": {
"flow_sid": "FW936f72c0eb8d3945d0d55c62465e37a8",
"data": {},
"channel": {
"address": "+1xxxxxxxxx2"
},
"sid": "FN955cdb12827f84c8af8fc9b5264e5a28"
}
}
I really can't figure out what I'm missing here? Has anyone run into this before? Is this something you can only do if you're using the SDK or does the additional parameter need to be passed in some other way?
It should be sent x-www-form-urlencoded.
From the documentation:
"Note: the JSON value must explicitly be passed as a string, not as a hash object. Depending on your particular HTTP library, you may need to add quotes or URL encode the JSON string."
Trigger a Twilio Studio Flow Execution via the REST API
I'm using Twilio Autopilot with Programmable Voice as Input Channel and I would like to record the entire conversation that the client has with the robot.
Where and how can I do it?
I'm using a twiML bin that redirects to the Autopilot URL.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Redirect method="POST">[autopilot url]</Redirect>
</Response>
Twilio developer evangelist here.
To record the call without the <Record> TwiML verb, you could
Serve with the AP connect verb <Response> <Connect> <Autopilot>...
Use the Call SID received in the response to that and use the call recording controls API to start recording the call.
Alternatively, you could use the Moment package in a Twilio function that is redirected from an Autopilot task.
For the task you want to record user input for, your Autopilot task code may look like this:
{
"actions": [
{
"collect": {
"name": "your-task-name",
"questions": [
{
"question": {
"say": "What's your first name?"
},
"name": "first_name",
"type": "Twilio.FIRST_NAME"
},
{
"question": {
"say": "How many people would you like the reservation to be for?"
},
"name": "number",
"type": "Twilio.NUMBER"
}
],
"on_complete": {
"redirect": "https://your-function-url.twil.io/your-function-name"
}
}
}
]
}
After redirecting to the Twilio Function, you could write some Node.js code with the Moment module that may look like this:
exports.handler = function(context, event, callback) {
const moment = require('moment');
let responseObject = {};
let memory = JSON.parse(event.Memory);
let first_name = memory.twilio.collected_data.your-task-name.answers.first_name.answer || 'to whom it may concern';
let number = memory.twilio.collected_data.your-task-name.answers.number.answer;
let message = "Ok " + first_name + "You said your group is of size " + number + "Thank you for booking with us";
ResponseObject = {
"actions":[
{ "say": { "speech": message } }
]};
callback(null, responseObject);
}
The code above saves the user's answers to each question your Autopilot assistant asks, expecting different types of responses. These Built-in Field Types include numbers, yes or no answers, dates, times, first names, last names, emails, months, US states, countries, cities, days of the week, currencies, languages, and more. You can also keep track of the question the Autopilot assistant asks in each Autopilot task.
There's more details in this Deep Table tutorial and this Facebook Messenger bot blog post (different communication platform, same code to parse user input.) Hope this helps!
I just created a channel via Slack Api using channels.create method. How do I add incoming webhook and get the URL programmatically? I have other tools that will use it further.
You can not create new incoming webhooks programmatically, but you don't have to. Just override the channel property on an existing incoming webhook for your current Slack team to use the new channel.
Example:
{
"text": "This is a line of text.\nAnd this is another one.",
"channel": "channel-name"
}
Note that this will only work for incoming webhooks defined via custom integrations, but not for those defined as part of a Slack app.
data = {
"attachments": [
{
"author_name": "[Alert] - A Jenkins Job is Already Running!",
"color": "#36a64f",
"title": "Android Jenkins Job",
"title_link": "http://xx.xxx.xxx.xxx/job/Mobile_Regression/",
"footer": "Android Build Attempted",
"ts": time.time()
}
],
"channel": "#channel"
}
json_params_encoded = json.dumps(data)
slack_response = requests.post(url=hook_url, data=json_params_encoded, headers={"Content-type": "application/json"})
I am trying to create a new channel using slack api https://api.slack.com/methods/channels.join but getting this response
info: ** API CALL: https://slack.com/api/channels.join
Response : { ok: false, error: 'user_is_bot' }
I tried this
controller.hears('hello', ['direct_message', 'direct_mention', 'mention'], function (bot, message) {
bot.api.channels.join({'name':'nag'}, function (err, response) {
console.log("Response : ",response);
})
});
If I am mistaken please let me know. I have started learning slack api.
The reason you are getting user_is_bot is that channels.join can not be used by a bot user. As it says in the documentation for this method:
user_is_bot: This method cannot be called by a bot user.
To create channel you will want to use channels.create. However, that method can also not be used by a bot user.
The common solution is to use the full access_token, not the bot_access_token that your Slack app received from Slack after installing it with OAuth for all methods that bot users can not use, e.g. creating a new channel.
Here is the example from the OAuth documentation on how the response from Slack with both tokens look like:
{
"access_token": "xoxp-XXXXXXXX-XXXXXXXX-XXXXX",
"scope": "incoming-webhook,commands,bot",
"team_name": "Team Installing Your Hook",
"team_id": "XXXXXXXXXX",
"incoming_webhook": {
"url": "https://hooks.slack.com/TXXXXX/BXXXXX/XXXXXXXXXX",
"channel": "#channel-it-will-post-to",
"configuration_url": "https://teamname.slack.com/services/BXXXXX"
},
"bot":{
"bot_user_id":"UTTTTTTTTTTR",
"bot_access_token":"xoxb-XXXXXXXXXXXX-TTTTTTTTTTTTTT"
}
}