AWS SNS / SMS: Accented characters look garbled on the phone - character-encoding

I'm sending a message containing accents like so:
sns.publish({ Message: 'Olá, Jean', PhoneNumber: '+55...' })
But it gets rendered Ol?ean. How can I fix this?
Platform: NodeJS.
aws-sdk version: 2.6.9.
SNS API version: 2010-03-31.

Related

SendGrid Inbound Parse japanese (encoding: shift_jis) text garbled

Currently we are using SendGrid Inbound Parse to receive emails.
We handle the Inbound Parse webhook request by Azure HttpTrigger function implmented in C# (.NET 6).
When the received email is in UTF-8 encoding, everything's okay.
However, when we tried to receive email in shift_jis encoding, headers are okay,
but japanese characters in text and html are garbled.
From Inbound Parse request, we got the charsets as below:
subject: UTF-8
to: UTF-8
from: UTF-8
cc: UTF-8
html: shift_jis
text: shift_jis
And the string we got directly from request.form["text"] (or "html") was already garbled like "�e�L�X�gshiftJis-007"
(should be "テキストshiftJis-007"), so we cannot use string in request directly.
Then we tried to convert (System.Text.Encoding.Convert method) it from charset encoding (shift_jis) to utf-8,
and the result was different from original string but still unreadable "?e?L?X?gshiftJis-007".
Our questions are:
When using C# HttpTrigger Azure function to handle Inbound Parse webhook request
(request data is passed through AspNetCore.)
What encoding is in html/text string in Inbound Parse webhook request
when the email is send in encoding other than UTF-8?
How to read text and html in shift_jis encoding (or other encodings excluding UTF-8)
correctlyfrom an Inbound Parse webhook request?
Twilio Developer Evangelist here. I would recommend reaching out to the support team because it requires to investigate the payload to figure out what is going on.
I also tried to replicate the issue on my end with using send_raw option. Here's the payload, and it does contain shift_jis characters. You may be able to process the payload manually.
(stripped X-Mailer info)
'Content-Type: text/plain; charset="shift_jis"\n' +
'X-Mailer: \n' +
'Content-Transfer-Encoding: quoted-printable\n' +
'\n' +
'\n' +
'=83e=83L=83X=83gshiftJis-007\n'

Rails w/ Google API Client: header field value cannot include CR/LF

ArgumentError in Users::OmniauthCallbacksController#google_oauth2
header field value cannot include CR/LF
Really unsure where this error is coming from.
I'm using ruby 2.5, Rails 5, and google-api-client 0.8.2
Any ideas how to fix or what information I can provide to make this question more informative?
Update: My logs show this when I am trying to authorize with Google's API
Google::APIClient::Request Sending API request get https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest {"User-Agent"=>"hello U/1.0.0 google-api-ruby-client/0.8.2 Mac OS X/10.13.4\n (gzip)", "Accept-Encoding"=>"gzip", "Content-Type"=>""}
And from my research, CRLF is "\r\n" characters, right?
So "User-Agent"=>"hello U/1.0.0 google-api-ruby-client/0.8.2 Mac OS X/10.13.4\n
is probably the issue.
So my question would be- how do I access User Agent in my request to fix this issue with Rails 5?
When using the Google::APIClient, the generated User-Agent may contains a CRLF. It can can be overridden in constructor. Example :
Google::APIClient.new(application_name: 'Foo', application_version: '1.0', user_agent: 'Foo/1.0 google-api-ruby-client/0.8.6 Linux/4.15.0-65-generic (gzip)')
You can modify the user_agent string to remove the CR/LF. I am using Rails 4.1.8 and google-api-client version `
#api_client = Google::APIClient.new(:application_name=>"Chronos", :application_version=>0)
# work around a bug that puts a CR/LF in the user agent string
#api_client.user_agent = #api_client.user_agent.gsub("\n", "")
Update gem google-api-client to version 0.20.0. It solves the problem but requires other changes to the application
Updating the version of the google-api-client gem did the trick for me.

Ruby - no implicit conversion of HTTParty::Response into String exotel api

I'm unable to fetch response or send request to exotel sms api using the provided documentation on exotel rubygem http://www.rubydoc.info/gems/exotel/0.2
The documentations says to fetch response as follows:
sms = Exotel::Sms.details(sms_id)
But when I do that with an sms_id, ex. sms_id='12345678901234567890'
like
sms = Exotel::Sms.details("12345678901234567890")
it gives an error
TypeError: no implicit conversion of HTTParty::Response into String
I do have httparty gem installed. How to solve this?
The library is tested with 0.9.0 version of httparty that used to respond with Hash for http requests and the code is assuming it is string if not Hash and that is why it is failing
Here is the line causing the problem
exotel/response.rb
Quick fix would be to use 'httparty=0.9.0'
You may do it by using
gem "httparty","0.9.0"
Here is a working sample code, please update the account_sid and token with yours
gem "httparty","0.9.0"
require "exotel"
account_sid = "testexotel"
token = "9dcb4*******************e1dc2174fc47"
Exotel.configure do |c|
c.exotel_sid = account_sid
c.exotel_token = token
end
sms = Exotel::Sms.details("40a7*********258d411898b18b")
puts sms.status
puts sms.date_sent

request.session['_csrf_token'] and meta tag csrf_token doesn't match

I have implemented real-time chat using websockets with Faye in Rails 4.2
Right now I can publish a message to channels using curl like:
curl http://localhost:3000/faye -d message={"channel":"/mychannel", "data": "my message"}'
To prevent this, I followed the guide http://faye.jcoglan.com/security/csrf.html
But client always got 401 error
[,…]
0: {id: "8l", channel: "/meta/handshake", error: "401::Access denied", successful: false, version: "1.0",…}
advice: {reconnect: "handshake"}
channel: "/meta/handshake"
error: "401::Access denied"
id: "8l"
successful: false
supportedConnectionTypes: ["long-polling", "cross-origin-long-polling", "callback-polling", "websocket", "eventsource",…]
version: "1.0"
I also debug token variables inside CsrfProtection extension. They always differ.
Started POST "/faye" for 127.0.0.1 at 2016-02-20 02:53:59 +0600
session_token: "nICoUB0sDiwmNqbRpr1kUM7LtyBybCiddThnZceU7UI="
message_token: "PO5gD5tPwVMZifrUCsk8xnJXUIRZkhOU/vQ+ujbmQAugbshfhmPPfz+/XAWsdFiWvJznpCv+OwmLzFnf8XKtSQ=="
Why they differ and how do I implement csrf protection?
The method from Rails code may help: token validation
Idea: on the page you have Base64 encoded value and you need to decode it

invalid byte sequence in UTF-8 with Rails flash messages

we use Rails 3 and Spree Commerce for our online shop and we have a payment provider, that returns errors in a redirect URL if some occur. When an error occurs, we present that string with flash messages to the user.
Yesterday, something didn't work, and the payment provider returned this string in the redirect URL, which should be presented to the user inside a flash message:
errormsg=Bitte+versuchen+Sie+es+sp%E4ter+nochmals.
I debugged a little bit, and the string looks like this when decoded (e.g. is written to flash[:error]):
Bitte versuchen Sie es sp\xE4ter nochmals.
And after that, an error is raised, when rails tries to render the flash message:
invalid byte sequence in UTF-8
Can someone tell me, how to fix this? The error should contain a german ä and not \xE4. I tried setting # encoding: utf-8 to the beginning of the controller and the view, but this doesn't help.
'Obviously, your payment provider uses ISO-8859-1 or similar to send german umlauts.
As your rails app uses UTF-8, you can convert the message of your provicder.
Assume you stored the message in variable msg, use
utf_msg = params[:errormsg].force_encoding('ISO-8859-1').encode('UTF-8')
you can also check, if the resulting encoding is valid:
uft_msg.valid_encoding?
and outpunt a different message to avoid errors.

Resources