Using xmpp4r_facebook gem facebook chat message not being sent - ruby-on-rails

I am using xmpp4r_facebook gem to send a message to a facebook friend using my facebook application. Please note I have xamp_login permission. The problem is the message is not being sent. I have followed some other instructions from stackoverflow and implemented as they instructed. But still no message is being sent. Please note, to check, I have changed the facebook application sandbox mode off and make it live. But still not working.
Any help possible?
Or any other library suggestions can you provide?
please let me know!
sender_uid = current_user.uid
receiver_uid = TaggedPerson.last.uid.to_s
sender_chat_id = "-#{sender_uid}#chat.facebook.com"
receiver_chat_id = "-#{receiver_uid}#chat.facebook.com"
message_body = "message body"
message_subject = "message subject"
jabber_message = Jabber::Message.new(receiver_chat_id, message_body)
jabber_message.subject = message_subject
client = Jabber::Client.new(Jabber::JID.new(sender_chat_id))
client.connect
client.auth_sasl(Jabber::SASL::XFacebookPlatform.new(client,
ENV.fetch('APP_ID'), current_user.oauth_token,
ENV.fetch('SECRET_KEY')), nil)
# 0
client.send(jabber_message)
# nil
client.close
# nil

Can you use "Jabber::debug = true" and give more info?

Related

BadDeviceToken when trying to send the notification (APN) with apnotic gem Rails

I am trying to fire a notification using gem 'apnotic'.
connection = Apnotic::Connection.development(cert_path: "#{Rails.root}/lib/mondofiPush.pem", cert_pass: "")
token = "5e67102820556ee177ffbe0a64ee3a391b89ac61ff2602c97587e838ef93cca"
notification = Apnotic::Notification.new(token)
notification.alert = "Notification from Apnotic!"
response = connection.push(notification)
But in response I get:
{"reason"=>"BadDeviceToken"} we checked that token if fine.
Can anybody please guide me to solve this?

How to send a reply to an email using MailCore2 in Swift?

I'm trying to use MailCore2 in my Swift iOS app, and at the moment; am trying to understand how to reply to an email.
Currently have something working where I can send new email messages, but am trying to figure out how to reply to an existing email.
I've seen a few different questions here asking for the same thing:
mailcore2 How to forward/reply email iOS
MailCore2 Reply / Forward
replyAllHeaderWithExcludedRecipients seems not working
But so far, I've not come across anything that actually ends up answering the question. Any help here appreciated!
I ended up figuring it out eventually:
var emailToReplyTo: MCOIMAPMessage!
emailToReplyTo = //the email message that you want to reply to
let reply = emailToReplyTo.header.reply(withExcludedRecipients: [])
let builder = MCOMessageBuilder()
builder.header = reply
builder.header.from = MCOAddress(displayName: "My Name", mailbox: "myemail#gmail.com")
builder.htmlBody = "Message body!"

Twilio WhatsApp messages are in 'queued' status

Okay so I got approval from WhatsApp and Twilio (after Facebook Business verification) to use the WhatsApp API for sending out appointment reminders to my clients. I configured the message templates and they got approved too. Check the image below:
I have written a code in Python where I pick my data from a PostgreSQL server hosted on cloud (using psycopg2) and then it sends out messages to the phone numbers fetched using a query. Here is the code:
from twilio.rest import Client
import psycopg2
import time
account_sid = 'AC54xxxxxxxxxxxxxxxxxxxxxxxxxxx'
auth_token = 'f1384yyyyyyyyyyyyyyyyyyyyyyyyyyy'
connection_string = ""
conn = psycopg2.connect(user = "xxxx",
password = "yyyyyy",
host = "zzzzzzzzzzzzzzz.zzzzzzzzzzzz",
port = "ABCD",
database = "some_db")
cur = conn.cursor()
cur.execute("""query to pick data""")
rows = cur.fetchall()
client_phone_list = []
phone_list_not_received = []
session_date_list = []
session_time_list = []
client_first_name_list = []
for row in rows:
session_date_list.append(row[0])
session_time_list.append(row[1])
client_first_name_list.append(row[2])
client_phone_list.append(row[3])
cur.close()
conn.close()
client = Client(account_sid, auth_token)
message_reminder_template = """Hello {},
This is a reminder about your session today at {}. Please be on time to utilize the full length of
the session and avoid distress :)
We look forward to taking care of you!"""
for i in range(len(client_phone_list)):
first_name = client_first_name_list[i]
appointment_time = session_time_list[i]
message_body = message_reminder_template.format(first_name, appointment_time)
print(message_body)
message = client.messages.create(body = str(message_body),
from_ = 'whatsapp:+1(mytwilionumber)',
to = 'whatsapp:+91'+client_phone_list[i])
time.sleep(10)
text_status = message.status
print(text_status)
Whenever I run this code the message status returned is always 'queued'. I have checked that I am not using the 'Test Credentials' but the 'Live Credentials'.
I have also checked the error_code and error_message which returns as NULL. So there is no error but the messages are not getting sent. How can I change that?
Any help would be hugely appreciated.
Also note that the message body used in the code above is approved as a template from WhatsApp.
Twilio developer evangelist here.
At the point that you make the API request to send the message the status will be returned to code as "queued". That's this point in your code here:
message = client.messages.create(body = str(message_body),
from_ = 'whatsapp:+1(mytwilionumber)',
to = 'whatsapp:+91'+client_phone_list[i])
What you do next will not work though:
time.sleep(10)
text_status = message.status
print(text_status)
Waiting 10 seconds and then reading the status from the message object that was returned when you created the message will still return "queued".
If you want to fetch the message status after 10 seconds to see if it has been sent then you will need to make a second call to the messages API, like so:
time.sleep(10)
latest_message = client.messages(message.sid).fetch()
print(latest_message.status)
For a more efficient method of keeping track of the status of your messages, check out this tutorial on receiving webhooks for message status updates.
Let me know if that helped at all.

Rpush notification fails to deliver

I am new to Rails. I am trying to send push notification using rpush gem.
I am following these steps:
n = Rpush::Gcm::Notification.new
n.app = Rpush::Gcm::App.find_by_name("android_app")
n.registration_ids = ["#{d.device_token}"]
n.data = { title: "#{self.title}"}
n.save!
The notification gets saved but is not getting delivered, and I get the following error description:
"Unable to deliver notification 10, received error (Failed to deliver to all recipients. Errors: NotRegistered.)"
Not able to understand the issue here. Please help me.
Thanks!
When you find above mentioned message in your log, means, as said #abielita and rpush wiki documentation, the identification_id GCM is using to send notification, is no more valid.
Device with (d.device_token) as registration token, is no more registered on GCM (Firebase) Service.
This message come for a specified reason: adapt your code to this condition.
Maybe is better destroy your "d" record !?
Becomes helpful Rpush.reflect in config/initializers/rpush.rb
Uncomment event notification on.gcm_invalid_registration_id and add your code inside block
e.g.
on.gcm_invalid_registration_id do |app, error, registration_id|
Device.where(registration_id: registration_id).take.destroy
end
and encloses your sending notification code inside a conditional check
unless(d.nil?)
n = Rpush::Gcm::Notification.new
n.app = Rpush::Gcm::App.find_by_name("android_app")
n.registration_ids = ["#{d.device_token}"]
n.data = { title: "#{self.title}"}
n.save!
end
I hope it help

how to receive mail and send notification to the user in rails?

I have been trying to receive emails in rails using IMAP and send a notification to user that new mail has come. I have a table namely "email" where i have to store the email information like message_from, message_to, message and i wanted to know how to fetch the emails from the gmail whenever a new mail comes in. And the following is the code
require 'net/imap'
require 'net/http'
imap = Net::IMAP.new('imap.gmail.com', 993, usessl = true, certs = nil, verify = false)
imap.login('sampleuser', 'password')
imap.select('INBOX')
imap.search(["NOT", "SEEN"]).each do |message_id|
emails = imap.fetch(mail,'RFC822')[0].attr['RFC822']
#mail = Email.new("from" => emails.from, "to" => emails.to)
#mail.save
end
but i cannot able to fetch the message_from or message_to or the message, it shows error as
TypeError (can't convert Symbol into Integer):
how can i get those details and i want to send notification to the user when a new entry is created in the table and clicking on that should take it to the page where i have to display the email.
How can i do this and should i be using something like scheduler to check if the new mail has come and if i am not reading the mail how can i identify that i have received the mail already and i do not want to duplicate. Please help me.
Your best bet on receiving emails is Griddler. It's easy to setup
You can send the email to the model you want and do the processing there.

Resources