I currently receive data from each call to a Twilio number that contains info like this:
{
"Called": "+xxxxxxxx",
"ToState": "CA",
"CallerCountry": "US",
"Direction": "inbound",
"Timestamp": "Sat, 25 Aug 2018 00:01:46 +0000",
"CallbackSource": "call-progress-events",
"CallerState": "CA",
"ToZip": "92111",
"SequenceNumber": "0",
"To": "+1xxxxxx",
"CallSid": "xxxxxxxxxxxxx",
"ToCountry": "US",
"CallerZip": "92117",
"CalledZip": "92111",
"ApiVersion": "2010-04-01",
"CallStatus": "completed",
"CalledCity": "SAN DIEGO",
"Duration": "1",
"From": "+1xxxxxxxxxx",
"CallDuration": "10",
"AccountSid": "xxxxxxxxxxxxx",
"CalledCountry": "US",
"CallerCity": "POWAY",
"ToCity": "SAN DIEGO",
"FromCountry": "US",
"Caller": "+1xxxxxxxxxxx",
"FromCity": "POWAY",
"CalledState": "CA",
"FromZip": "92117",
"FromState": "CA",
}
This is provided at the end of each call to my server. However I need to fetch historical data to reconcile some missing info so I attempted to use the call log api as:
const calls = await twilio.calls.list()
This returns a different type of structure:
CallInstance {
accountSid: 'xxxxxxxxxx',
annotation: null,
answeredBy: null,
apiVersion: '2010-04-01',
callerName: null,
dateCreated: 2018-08-29T17:20:51.000Z,
dateUpdated: 2018-08-29T17:21:52.000Z,
direction: 'inbound',
duration: '61',
endTime: 2018-08-29T17:21:52.000Z,
forwardedFrom: '+xxxxxxxxxx',
from: '+xxxxxxxxxx',
fromFormatted: 'xxxxxxxxxx,
groupSid: null,
parentCallSid: null,
phoneNumberSid: 'xxxxxxxxxx',
price: -0.017,
priceUnit: 'USD',
sid: 'xxxxxxxxxx',
startTime: 2018-08-29T17:20:51.000Z,
status: 'completed',
subresourceUris:
{ notifications:
'/2010-04-01/Accounts/xxxxxxxxxx/Calls/xxxxxxxxxx/Notifications.json',
recordings:
'/2010-04-01/Accounts/xxxxxxxxxx/Calls/xxxxxxxxxx/Recordings.json' },
to: '+17603137608',
toFormatted: '(760) 313-7608',
uri:
'/2010-04-01/Accounts/xxxxxxxxxx/Calls/xxxxxxxxxx.json'
}
However this has no caller location data such as the city/country. Is there another API call to get the location data or am I left to my own devices by analyzing the phone number?
So after diving into it it doesn't appear to be possible. I ended up using something like the Google phone lib to analyze the number and return country.
Related
I am trying to access a Netsuite Ruby Hash (Netsuite gem) and return orders which need updating from the db, the process uses two service objects, one to get the orders from db, (ListOrdersService), and the this file to compare those against modified ones in Netsuite. Is all working except I am having problems getting some of the nested values in Netsuite in to the output. Code is below with a troublesome item commented out. Its just an each method which compares dates then puts the needed orders in returned value.
def process_order_updates
get_order_updates = []
# Get all our open orders from DB
bj_open_orders = ListOrdersService.new.call
# Get all identical open orders from Netsuite
bj_open_orders.each do |item|
netsuite_sales_orders = NetSuite::Records::SalesOrder.get(item['sales_order_internal_id'])
# Compare the last modified date from Netsuite to the last checked date from app DB
if netsuite_sales_orders.present? && netsuite_sales_orders.last_modified_date > item['last_checked_date']
# If the last modified date is newer, then we create a new hash with the updated order info
get_order_updates << {
sales_order_internal_id: item['sales_order_internal_id'],
order_status: item['order_status']
# quantity_fulfilled: item['items_list']['item']['quantity_fulfilled']
}
puts "still open order #{item['sales_order_internal_id']} needs to be updated, it was last checked by at #{item['last_checked_date']} but it was just modified, on #{netsuite_sales_orders.last_modified_date}"
end
end
puts "Here are the orders that need to be updated: #{get_order_updates}"
end
The Netsuite file code I am referencing is below, and trying to get quantity_fulfilled, quantity_billed, and some others in the file. items_list is a top level item
"item_list": {
"list": [
{
"attributes": {
"item": {
"internal_id": "110",
"external_id": null,
"type": null,
"attributes": {
"name": "000002 Kerosene (UN1223) 3.PGIII (D/E)"
}
},
"expand_item_group": false,
"quantity": "1000.0",
"units": {
"internal_id": "1",
"external_id": null,
"type": null,
"attributes": {
"name": "ltr"
}
},
"description": "Kerosene (UN1223) 3.PGIII (D/E)",
"price": {
"internal_id": "-1",
"external_id": null,
"type": null,
"attributes": {}
},
"rate": "0.81",
"amount": "810.0",
"is_closed": false,
"gross_amt": "850.5",
"line": "1",
"cost_estimate_type": "_averageCost",
"cost_estimate": "900.79",
"quantity_back_ordered": "0.0",
"quantity_billed": "0.0",
"quantity_committed": "1000.0",
"quantity_fulfilled": "0.0",
"tax1_amt": "40.5",
"tax_code": {
"internal_id": "2214",
"external_id": null,
"type": null,
"attributes": {
"name": "VAT:RDR-5%"
}
},
Any tips on how to get those items, directly or with a hashmap welcome Thanks
I am trying to locate emails in mailboxes that contain certain email header information. Utilizing the Microsoft Graph Explorer I am able to extract all 'internetMessageHeaders' for emails:
https://graph.microsoft.com/v1.0/me/mailfolders('Inbox')/messages?$select=internetMessageHeaders
Which results in:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('xxxxxxx-ef44-425b-b7a5-xxxxxxxxxx')/mailFolders('Inbox')/messages(internetMessageHeaders)",
"value": [
{
"#odata.etag": "W/\"xxxxxxxxxxxZXLAAASEk7/\"",
"id": "kSlaEZXLAAASFWUWAAA="
},
{
"#odata.etag": "W/\"EZXLAAAKjXG0\"",
"id": "AKj3OcAAA=",
"internetMessageHeaders": [
{
"name": "Received",
"value": "from x.x.prod.outlook.com (x:x:x:x::x) by x.x.prod.outlook.com with HTTPS; Tue, 23 Nov 2021 22:13:31 +0000"
},
{
"name": "Received",
"value": "from x.x.prod.outlook.com (x:x:x:x::x) by x.x.prod.outlook.com (x:x:x:x::x) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id x; Tue, 23 Nov 2021 22:13:28 +0000"
},
{
"name": "Received",
"value": "from x.x.prod.protection.outlook.com (x:x:x:x::x) by x.outlook.office365.com (x:x:x:x::x) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id x via Frontend Transport; Tue, 23 Nov 2021 22:13:27 +0000"
},
{
"name": "Received",
"value": "from x (x.x.x.x) by x.mail.protection.outlook.com (x.x.x.x) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id x via Frontend Transport; Tue, 23 Nov 2021 22:13:26 +0000"
},
{
"name": "Authentication-Results",
"value": "spf=pass (sender IP is x.x.x.x) smtp.mailfrom=senderdomain.com; dkim=pass (signature was verified) header.d=senderdomain.com;dmarc=pass action=none header.from=senderdomain.com;compauth=pass reason=100"
},
{
"name": "Received-SPF",
"value": "Pass (protection.outlook.com: domain of senderdomain.com designates x.x.x.x as permitted sender) receiver=protection.outlook.com; client-ip=x.x.x.x; helo=senderdomain.com;"
},
{
"name": "Date",
"value": "Tue, 23 Nov 2021 22:13:24 +0000"
},
{
"name": "DKIM-Signature",
"value": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=senderdomain.com;s=senderdomain; t=1637705605;bh=xxxxxxx;h=Date:To:From:Reply-To:Subject:From;b=[redacted]="
},
{
"name": "Subject",
"value": "Test #3"
},....
With the JSON results available, is it possible to use the $filter operation to search any of the value fields for specific conditions?
For example:
how would I search/filter the Received-SPF field for a Pass or Fail condition?
how would I search/filter any of the Received fields for a specific string?
how would I combine #1 and #2 with an AND logic in a single filter?
I have looked at the Advanced Query references, yet I am not able to find any reference on how to filter for values inside the internetMessageHeaders JSON structure.
Any thoughts or pointers on how to search the header information fields would be much appreciated.
The end-goal is to only return emails where the $filter criteria on the email header fields is met.
You could filter on filter singleValueExtendedProperties of type 0x007D which returns all internetmessageheaders as one object:
"singleValueExtendedProperties": [
{
"id": "String 0x7d",
"value": "{headerName}: {headerValue}; {headerName}: {headerValue}; ....."
}
]
If you want to use this filter:
$filter=internetMessageHeaders/any(r:r/name eq 'Received-SPF')
use this instead
$filter=singleValueExtendedProperties/any(r:r/id eq 'String 0x007D' and contains(r/value,'Received-SPF'))
If you want to avoid parsing that one long string of headers, you can add
$select=internetMessageHeaders
and you get them as one long array of key/value objects
The property InternetMessageHeaders does not support filtering.
You can try this request
GET https://graph.microsoft.com/v1.0/me/mailfolders('Inbox')/messages?$select=internetMessageHeaders&$filter=internetMessageHeaders/any(r:r/name eq 'Received-SPF')
But it will return ErrorInvalidProperty
I am trying to build a GET request to only pull specific data but I am having problems with utilizing OData.
Objects pulled from the API looks like this:
{
"PostalCode": "48103",
"FranchiseId": 397,
"Franchise": {
"ConceptId": 1,
"CreatedDateTime": "2015-10-20T18:36:46.353",
"ModifiedDateTime": "2018-01-26T14:35:33.447",
"DeletedDateTime": null,
"DoingBusinessAs": "Appliance.inc",
"Status": "Active",
"IsOwned": true,
"FranchiseeName": "Appliance Inc - Ann Arbor, MI - MLY 1001",
"LicenseNumber": "ML89023",
"City": "Ann Arbor",
"StateAbbr": "MI",
"PostalCode": "48104",
"ContactFirstName": "Doug",
"ContactLastName": "Smith",
"Country": "United States"
}
},
I am doing this GET request to get that data:
#url#&$expand=Franchise&$select=FranchiseId, PostalCode
I am using &$expand=Franchise just because I need the "FranchiseeName" from Franchise object but I don't want to pull the rest of the data of that object.
How can I write the request so I only pull three fields: PostalCode, FranchiseId, FranchiseeName. The object should look something like this:
{
"PostalCode": "48103",
"FranchiseId": 397,
"FranchiseeName": "Appliance.inc"
}
I assume #url# is a placeholder for the OData URI to your entity, e.g. http://server/odata/entityName.
The following URL should get the data you need:
http://server/odata/entityName?$select=PostalCode,FranchiseId&$expand=Franchise($select=FranchiseeName)
That should return only the required data, but still having the same structure as the full data, e.g:
{
"PostalCode": "48103",
"FranchiseId": 397,
"Franchise": {
"FranchiseeName": "Appliance.inc"
}
}
I am trying to retrieve data from 2 buckets, no error but nothing shows up (I do have documents I need in these buckets).
1st bucket: a_bucket
here is the document I am interested in (I do have 3 different docs)
author_ID document:
{
"author_ID": 1,
"profil_creation_date": "2017/01/01/01:23:05/+5",
"prefix": "Mr.",
"first_name": "Dylan",
"middle_name_s": "Alfred",
"last_name": "Kerr",
"date_of_birth": "1974/01/02",
"sex": "M",
"marital_status": "Single",
"mobile_phone": "(860) 231-3336",
"address": [
{
"address_1": {
"address_ID": 1,
"home_address": "338 Counts Lane",
"city": "West Hartford",
"province/state": "CT",
"postal_code": "06105"
}
},
{
"address_2": {
"address_ID": 2,
"work_address": "977 Copperhead Rd",
"city": "Newington",
"province/state": "CT",
"postal_code": "06111"
}
}
]
}
2nd bucket: b_bucket
here are the 2 docs I am interested in:
p_output_ID document:
{
"p_output_ID": 1,
"author_ID": 2,
"overall_score": 4.41,
"status": {
"r_status_first": "TRUE",
"r_status_second": "FALSE",
"r_status_third": "YES",
"y_status_second": "TRUE",
"y_status_third": "FALSE",
"g_status_third": "TRUE"
}
}
timing_ID document:
{
"timing_ID": 1,
"p_output_ID": 1,
"author_ID": 1,
"date_and_time": "2017-06-06/23:45:25.25/+5",
"time_in_seconds": 12525,
"incremental_time_in_seconds": "time_in_seconds",
"current_state_and_duration": {
"state": "RED",
"duration_in_seconds": 33333
}
}
my goal is to grab these informations in one query ():
prefix, first_name, middle_name_s, last_name (from author_ID document in a_bucket)
overall_score (from p_output_ID document in b_bucket)
date_and_time, state (from timing_ID document in b_bucket)
Here is my query:
select p2.current_state_and_duration.state, p1.overall_score, p2.date_and_time
from proc_data_bucket p1 USE KEYS "p_output_ID"
JOIN proc_data_bucket p2 ON KEYS "author_ID";
The syntax is OK, but I am getting no data
Please help me with that...
CREATE INDEX ix1 ON b_bucket(timing_ID);
SELECT p1.prefix, p1.first_name, p1.middle_name_s, p1.last_name,
p2.date_and_time,p2.state,
p3.overall_score
FROM b_bucket p2
JOIN a_bucket p1 ON KEYS ("author_" || TO_STRING(p2.author_ID))
JOIN b_bucket p3 ON KEYS ("p_output_" || TO_STRING(p2.p_output_ID))
WHERE p2.timing_ID BETWEEN 10 AND 50;
I want to send MMS using Twilio REST API. The message was sent successfully However, I am not able to get the unique MessageSid of the sent message.
I have already tried with $result->sid and $result->messageSid.
Current Code
$result= $client->account->messages->create(
$to, array('from' => $from,
'body' => $message,
'mediaUrl' => $mediaurl
));
if (isset($result->messageSid))
return $result->messageSid;
else
return "";
Is there anything i am doing wrong ?
Twilio developer evangelist here.
If you check the output for the first code sample on the documentation page for sending messages with Twilio then you will see that the returned JSON should have a sid property. Like this:
{
"sid": "MMc781610ec0b3400c9e0cab8e757da937",
"date_created": "Mon, 19 Oct 2015 07:07:03 +0000",
"date_updated": "Mon, 19 Oct 2015 07:07:03 +0000",
"date_sent": null,
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"to": "+15558675309",
"from": "+15017250604",
"body": "This is the ship that made the Kessel Run in fourteen parsecs?",
"status": "queued",
"num_segments": "1",
"num_media": "1",
"direction": "outbound-api",
"api_version": "2010-04-01",
"price": null,
"price_unit": "USD",
"error_code": null,
"error_message": null,
"uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc781610ec0b3400c9e0cab8e757da937.json",
"subresource_uris": {
"media": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc781610ec0b3400c9e0cab8e757da937/Media.json"
}
}
I just used similar code to you (I didn't send a media URL) and could echo $result->sid.
$result = $client->account->messages->create(
'MY_NUMBER',
array(
'from' => 'MY_TWILIO_NUMBER',
'body' => "Hey Jenny! Good luck on the bar exam!"
)
);
echo $result->sid;
Let me know if that helps.