How do i get a unique 'id' for my conversation between my twilio end-point and the person texting to my end-point - twilio

Twilio API / TWIML
when a user responds to my text (via text) and i receive their answer to my end-point, how do i identify the sender?
at first i thought it would be the 'sid', but it is not.. I cannot find an 'conversation_id' that exists both in the 'sending' and the 'responding' that could alert my end-point who the sender is.
when i send a text from my server, the response looks like:
{ sid: 'MMf9...',
date_created: 'Thu, 18 Aug 2016 03:24:50 +0000',
date_updated: 'Thu, 18 Aug 2016 03:24:50 +0000',
date_sent: null,
account_sid: '...',
to: '...,
from: '...',
messaging_service_sid: '...',
body: 'Hi. this is an anonymous text from my server',
status: 'accepted',
num_segments: '1',
num_media: '1',
direction: 'outbound-api',
api_version: '2010-04-01',
price: null,
price_unit: null,
error_code: null,
error_message: null,
uri: '/2010-04-01/Accounts/...../Messages/......json',
subresource_uris: { media: '/2010-04-01/Accounts/...../Messages/...../Media.json' },
dateCreated: Thu Aug 18 2016 03:24:50 GMT+0000 (UTC),
dateUpdated: Thu Aug 18 2016 03:24:50 GMT+0000 (UTC),
dateSent: null,
accountSid: '....',
messagingServiceSid: '.....',
numSegments: '1',
numMedia: '1',
apiVersion: '2010-04-01',
priceUnit: null,
errorCode: null,
errorMessage: null,
subresourceUris: { media: '/2010-04-01/Accounts/..../Messages/..../Media.json' } }
When I respond with a text from my phone back to my server, my end-point receives...
{
"ToCountry": "US",
"ToState": "IL",
"SmsMessageSid": "SMe....",
"NumMedia": "0",
"ToCity": "Chicago",
"FromZip": "60626",
"SmsSid": "SMe....",
"FromState": "IL",
"SmsStatus": "received",
"FromCity": "CHICAGO",
"Body": "Try",
"FromCountry": "US",
"To": "....",
"MessagingServiceSid": "....",
"ToZip": "",
"NumSegments": "1",
"MessageSid": "SMe...",
"AccountSid": "...",
"From": "...",
"ApiVersion": "2010-04-01"
}
as you can see the sid in the original sms starts with MMf9... and all the ids in my phone's response start with SMe...
I was hoping for some conversation-id in the sending and responding would be there so that on my end-point, i could create a database entry for the conversation, and store the response of my user from the conversation. But now since there is no conversation_id between sender & receiver, I have no idea where to store the conversation and i have no idea who my server is sending responses to.

since i get the 'to' phone number in the twilio meta-data, that is a way to identify the user.
Since Twilio does let you add custom 'meta-data' to the text message the user would need to respond with extra text in the text message itself to identify the 'conversation', for example:
'John, do you think the winner should be: A, B or C? Add your voter-id to the response: 43z'
Then the user would need to text back: B 43z.
You end-point would identify the answer 'B', and '43z' would identify the respondent as 'John' (supposing you have a database look-up mapping John to 43z on your sever).
Then you can get a total count for who the winner should be, and also know each user's response for the conversation.

Related

Gmail LodgingReservation Email Markup doesn't work

I try to use LodgingReservation Markup.
Documentation says that I can send email from own gmail mailbox to the same mailbox for testing.
I prepared simple test email:
<html>
<head>
</head>
<body>
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "LodgingReservation",
"reservationNumber": "abc456",
"reservationStatus": "http://schema.org/Confirmed",
"underName": {
"#type": "Person",
"name": "John Smith"
},
"reservationFor": {
"#type": "LodgingBusiness",
"name": "Hilton San Francisco Union Square",
"address": {
"#type": "PostalAddress",
"streetAddress": "333 O'Farrell St",
"addressLocality": "San Francisco",
"addressRegion": "CA",
"postalCode": "94102",
"addressCountry": "US"
},
"telephone": "415-771-1400"
},
"checkinDate": "2027-04-11T16:00:00-08:00",
"checkoutDate": "2027-04-13T11:00:00-08:00"
}
</script>
test
</body>
</html>
Email markup Tester can parse it successfully. But when I send the email and check it in my Inbox, it doesn't show card with reservation's information.
Origin message:
Return-Path: <kaba.nitesoft#gmail.com>
Received: from MSI ([90.189.151.28])
by smtp.gmail.com with ESMTPSA id q16-20020a2e84d0000000b0025e71cdb753sm287017ljh.46.2022.08.09.23.49.57
for <kaba.nitesoft#gmail.com>
(version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
Tue, 09 Aug 2022 23:49:58 -0700 (PDT)
Message-ID: <62f35516.2e0a0220.3adbf.15f2#mx.google.com>
Date: Tue, 09 Aug 2022 23:49:58 -0700 (PDT)
X-Google-Original-Date: 10 Aug 2022 13:49:58 +0700
MIME-Version: 1.0
From: kaba.nitesoft#gmail.com
To: kaba.nitesoft#gmail.com
Subject: Confirmation
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64
PGh0bWw+DQoJCQkJCQkJCTxoZWFkPiANCgkJCQkJCQkJPC9oZWFkPg0KCQkJCQkJCQk8
Ym9keT4NCgkJCQkJCQkJCQk8c2NyaXB0IHR5cGU9ImFwcGxpY2F0aW9uL2xkK2pzb24i
Pg0KCQkJCQkJCQkJCXsNCgkJCQkJCQkJCQkgICJAY29udGV4dCI6ICJodHRwOi8vc2No
ZW1hLm9yZyIsDQoJCQkJCQkJCQkJICAiQHR5cGUiOiAiTG9kZ2luZ1Jlc2VydmF0aW9u
IiwNCgkJCQkJCQkJCQkgICJyZXNlcnZhdGlvbk51bWJlciI6ICJhYmM0NTYiLA0KCQkJ
CQkJCQkJCSAgInJlc2VydmF0aW9uU3RhdHVzIjogImh0dHA6Ly9zY2hlbWEub3JnL0Nv
bmZpcm1lZCIsDQoJCQkJCQkJCQkJICAidW5kZXJOYW1lIjogew0KCQkJCQkJCQkJCSAg
ICAiQHR5cGUiOiAiUGVyc29uIiwNCgkJCQkJCQkJCQkgICAgIm5hbWUiOiAiSm9obiBT
bWl0aCINCgkJCQkJCQkJCQkgIH0sDQoJCQkJCQkJCQkJICAicmVzZXJ2YXRpb25Gb3Ii
OiB7DQoJCQkJCQkJCQkJICAgICJAdHlwZSI6ICJMb2RnaW5nQnVzaW5lc3MiLA0KCQkJ
CQkJCQkJCSAgICAibmFtZSI6ICJIaWx0b24gU2FuIEZyYW5jaXNjbyBVbmlvbiBTcXVh
cmUiLA0KCQkJCQkJCQkJCSAgICAiYWRkcmVzcyI6IHsNCgkJCQkJCQkJCQkgICAgICAi
QHR5cGUiOiAiUG9zdGFsQWRkcmVzcyIsDQoJCQkJCQkJCQkJICAgICAgInN0cmVldEFk
ZHJlc3MiOiAiMzMzIE8nRmFycmVsbCBTdCIsDQoJCQkJCQkJCQkJICAgICAgImFkZHJl
c3NMb2NhbGl0eSI6ICJTYW4gRnJhbmNpc2NvIiwNCgkJCQkJCQkJCQkgICAgICAiYWRk
cmVzc1JlZ2lvbiI6ICJDQSIsDQoJCQkJCQkJCQkJICAgICAgInBvc3RhbENvZGUiOiAi
OTQxMDIiLA0KCQkJCQkJCQkJCSAgICAgICJhZGRyZXNzQ291bnRyeSI6ICJVUyINCgkJ
CQkJCQkJCQkgICAgfSwNCgkJCQkJCQkJCQkgICAgInRlbGVwaG9uZSI6ICI0MTUtNzcx
LTE0MDAiDQoJCQkJCQkJCQkJICB9LA0KCQkJCQkJCQkJCSAgImNoZWNraW5EYXRlIjog
IjIwMjctMDQtMTFUMTY6MDA6MDAtMDg6MDAiLA0KCQkJCQkJCQkJCSAgImNoZWNrb3V0
RGF0ZSI6ICIyMDI3LTA0LTEzVDExOjAwOjAwLTA4OjAwIg0KCQkJCQkJCQkJCX0NCgkJ
CQkJCQkJCQk8L3NjcmlwdD4NCgkJCQkJCQkJCXRlc3QNCgkJCQkJCQkJPC9ib2R5Pg0K
CQkJCQkJCTwvaHRtbD4=
What is wrong? How I can test markup correctly?
Another question:
If email contains attached receipt in pdf-format, Gmail shows reservation's card by parsed data from attached file. It's problem that Gmail parses it incorrectly (for instance it shows incorrect CheckoutDate). So, can I disable this behavior? Or how I can format pdf document that it will be parsed correctly?

Rails, how to sort a collection keeping a specific value at the end

I have an active record collection of some objects...
#<CoverElement:0x00007f87a4d78718
id: 312,
title: "Title 1",
link: "",
coverable_id: 35001,
coverable_type: "Article",
created_at: Thu, 07 May 2020 16:55:00 CEST +02:00,
updated_at: Thu, 07 May 2020 16:55:00 CEST +02:00,
cover_id: 4,
format: "small",
custom_image: nil,
position: 2,
second_title: nil,
second_title_url: nil>,
#<CoverElement:0x00007f87a4d6fde8
id: 313,
title: "Title 2",
link: "",
coverable_id: 35010,
coverable_type: "Article",
created_at: Thu, 07 May 2020 16:55:00 CEST +02:00,
updated_at: Sun, 22 Nov 2020 19:33:39 CET +01:00,
cover_id: 4,
format: "horizontal",
custom_image: nil,
position: 3,
second_title: nil,
second_title_url: nil>
For the desktop version of the website I use the position as order, but I need another order for the mobile version.
I need to sort by format and "small" must be the last.
Basically formats can be: "large", "vertical", "horizontal" and "small".
I try with
#elements.reorder('format ASC')
and it works but of course it keep the order "horizontal", "large", "vertical" and "small"
Every object with "small" as format must be at the end. Is there a way to do this or I have to write a custom sort method?
you will need another sort method for the mobile version. However if you sort by format, it will do an alphanumeric sort, which will not give you the results you want ("small" is last).
There are a couple of ways to get the order you want:
first way is to recast the format column as an enum, so that the database contains integer values iso strings:
class CoverElement < ActiveRecord::Base
enum format: [ :large, :vertical, :horizontal, :small ]
end
if this is not possible, you can do it with an sql snippet something like this:
order = <<-ORD.squish
CASE
WHEN 'format'='large' THEN 4
WHEN 'format'='vertical' THEN 3
WHEN 'format'='horizontal' THEN 2
WHEN 'format'='small' THEN 1
END
ORD
CoverElement.order(order)

Randomly started to get 400 "Invalid request" error: "The provided encoding is not supported."

Starting around 00:10 UTC on Saturday 30th Jan 2021 we've started to see some of our cron jobs that update Microsoft shared calendar entries randomly return a 400 with the following error in the returned JSON contents:
'{ "error": { "code": "invalidRequest", "message": "The provided encoding is not supported." } }',
These appear randomly - if I rerun the command that created it there a good chance it will work just fine. Our cron job runs every hour (it's maintaining a share calendar of approved changes from our change management system) and the events it fails on appear to be different on every run.
Has something changed with Graph API over the weekend or are Microsoft's server experiencing heavy load? This seems like a really weird error message to get from an overloaded service though - I've gone down the rabbit hole of trying to work out what encoding it's talking about without any luck (especially as debugging is tricky because re-running calendar entry scripts by hand often works!). Searching for 'Microsoft Graph API "The provided encoding is not supported"' hasn't really thrown much up either so I'm a bit stumped now. Ideas anyone?
EDIT: The request is being made from a Perl script using LWP to PATCH to the https://graph.microsoft.com/v1.0/users/<user-id>/calendars/<calendar-id>. Here's an example of the dump of the object structure when we get the error (with the bearer key deleted obviously!). This contains everything being sent and everything being returned:
[69295] [Mon Feb 1 08:10:07 2021] [warning]: Event creation failed. LWP UA response object:
$VAR1 = bless( {
'_protocol' => 'HTTP/1.1',
'_content' => '{ "error": { "code": "invalidRequest", "message": "The provided encoding is not supported." } }',
'_rc' => 400,
'_headers' => bless( {
'connection' => 'close',
'client-response-num' => 1,
'date' => 'Mon, 01 Feb 2021 08:10:07 GMT',
'client-ssl-cert-issuer' => '/C=US/O=Microsoft Corporation/CN=Microsoft Azure TLS Issuing CA 01',
'client-ssl-cipher' => 'ECDHE-RSA-AES128-GCM-SHA256',
'client-peer' => '20.190.169.24:443',
'strict-transport-security' => 'max-age=31536000',
'content-length' => '95',
'::std_case' => {
'client-response-num' => 'Client-Response-Num',
'client-ssl-cert-issuer' => 'Client-SSL-Cert-Issuer',
'client-ssl-cipher' => 'Client-SSL-Cipher',
'client-peer' => 'Client-Peer',
'strict-transport-security' => 'Strict-Transport-Security',
'client-date' => 'Client-Date',
'client-ssl-cert-subject' => 'Client-SSL-Cert-Subject',
'client-ssl-socket-class' => 'Client-SSL-Socket-Class'
},
'client-date' => 'Mon, 01 Feb 2021 08:10:07 GMT',
'content-type' => 'application/json',
'client-ssl-cert-subject' => '/C=US/ST=WA/L=Redmond/O=Microsoft Corporation/CN=graph.microsoft.com',
'client-ssl-socket-class' => 'IO::Socket::SSL'
}, 'HTTP::Headers' ),
'_msg' => 'Bad Request',
'_request' => bless( {
'_content' => '{"extensions":[{"#odata.type":"Microsoft.Graph.OpenTypeExtension","RTTicketId":"236595","extensionName":"uk.ac.lboro.lunet.RTTicketId"}],"body":{"content":"<a href=\'https://servicedesk.lboro.ac.uk/Changes/Normal.html?id=236595\'>Change details in RT</a>.<br><br><h2>Test</h2><h3>Risk Level: Low</h3>","contentType":"HTML"},"singleValueExtendedProperties":[{"value":"236595","id":"String {E6F70170-9BED-11E8-8CBC-CDC132C02D95} Name RTTicketId"}],"subject":"RT Ticket# 236595 Test (Drafting (draft))","showAs":"tentative","end":{"timeZone":"UTC","dateTime":"2021-01-29 17:00:00"},"start":{"timeZone":"UTC","dateTime":"2021-01-29 07:00:00"}}',
'_uri' => bless( do{\(my $o = 'https://graph.microsoft.com/v1.0/users/8c0729fb-fdd8-4c47-afdd-6319d7f53527/calendars/AAMkADcyNzFmM2NmLTQwNWUtNDdkYi05NjBkLTMyY2Y0YWZmNjNjOABGAAAAAADLxa7s4pdTQYKigJvn9tIVBwCQ07ZtjCb-RJqL4KgdwIpWAAAA2V50AABdqLP0L9GOTKSkX7kyfyLXACFn_IIFAAA=/events/AAMkADcyNzFmM2NmLTQwNWUtNDdkYi05NjBkLTMyY2Y0YWZmNjNjOABGAAAAAADLxa7s4pdTQYKigJvn9tIVBwCQ07ZtjCb-RJqL4KgdwIpWAAAA2V53AACCh71i_SZfT6deBOa2tmDIAAW36HLpAAA=')}, 'URI::https' ),
'_headers' => bless( {
'user-agent' => 'libwww-perl/6.49',
'content-type' => 'application/json; charset=utf8',
'::std_case' => {
'if-ssl-cert-subject' => 'If-SSL-Cert-Subject'
},
'authorization' => 'Bearer <deleted>'
}, 'HTTP::Headers' ),
'_method' => 'PATCH',
'_uri_canonical' => $VAR1->{'_request'}{'_uri'}
}, 'HTTP::Request' )
},
I was facing the same issue, but executed a totally different Graph call: My call creates a Microsoft Team and has been successfully working for years... For the last few days, it randomly fails with the same error Jon mentioned.
I made sure that the JSON which is sent as the Payload of the Graph request always gets serialized as UTF-8 encoded string... Even that I cannot be sure that this fixed the issue, I didn't observe errors since then...

how will be the body of the recurring order for paypal checkout api

I have a rails application and now im trying to integrate with the Paypal for subscription.
I did a successful checkout with a single non recuring product using paypal checkout api.
My body for the order was
body = {
intent: 'CAPTURE',
application_context: {
return_url: "#{Rails.application.secrets.app_host}#{return_path}",
cancel_url: "#{Rails.application.secrets.app_host}#{cancel_path}"
},
purchase_units: [
{
amount: {
currency_code: 'USD',
value: '220.00'
}
}
]
}
I have my required plan saved in db:
#<Plan id: 6, name: "Daimond", fee: 45, created_at: "2019-08-19 08:40:13", updated_at: "2019-10-11 03:42:26", recuring: true, period: "Month", cycles: 12>
How will be the body for this kind of recurring orders?
Once you have a Plan, subscriptions need to be approved by the payer. The best way to get that approval is discussed in Step 4 here: https://developer.paypal.com/docs/subscriptions/integrate/#4-create-a-subscription

Record Persistence in Neo4j.rb 8.0.x

I am in the process of upgrading to Neo4j.rb version 8. After following the instructions in the upgrade guide, specs that were passing before are now failing.
Specifically, count, persisted?, all, last and find seem to have come unhinged from each other. I can create an account, see that is is persisted, see it if I count accounts, but not if I look for the last account, or all accounts, or try to find it from its id.
Output from console session below. Am I crazy?
[1] pry> account = Account.create(company_name: "Acme Corporation, LLC", street_address: "1234 Fake Lane", city: "Pleasantville", state: "CA", zip: "12345", country: "United States", phone: "555-555-5555", contact_name: "Some Guy", contact_phone: "123-456-7890", contact_email: "someguy#acmecorp.com")
=> #<Account uuid: "30c44118-ac45-4559-b63b-8e82fafb16cd", city: "Pleasantville", company_name: "Acme Corporation, LLC", contact_email: "someguy#acmecorp.com", contact_name: "Some Guy", contact_phone: "123-456-7890", country: "United States", created_at: Thu, 23 Mar 2017 19:13:52 +0000, phone: "555-555-5555", remote_id: nil, state: "CA", street_address: "1234 Fake Lane", updated_at: Thu, 23 Mar 2017 19:13:52 +0000, zip: "12345">
[2] pry> account.persisted?
=> true
[3] pry> Account.count
=> 1
[4] pry> Account.last
=> nil
[5] pry> Account.find(account.id)
Neo4j::ActiveNode::Labels::RecordNotFound: Couldn't find Account with 'uuid'=30c44118-ac45-4559-b63b-8e82fafb16cd
And the answer is....... RESTART YOUR COMPUTER AND EVERYTHING WORKS!!!111
In reality the problem was that somewhere along the line I deleted the database rather than stopping it, and then installed a new copy.

Resources