Using OsaScript to send Imessage without having a buddy ID - imessage

Can someone show me how I would be able to send a message to someone who I have not messaged using message previously. When I use the code below I get the error: execution error: Messages got an error: Can’t get buddy id "..." if I haven't messaged them previously..
on run {targetBuddyPhone, targetMessage}
tell application "Messages"
set targetService to service "SMS"
set targetBuddy to buddy targetBuddyPhone of targetService
send targetMessage to targetBuddy
end tell
end run
Thank you in advance

Related

Twilio whatsapp message fails even when matches the approved template

I am trying to send a whatsapp message via Twilio Business Account, from a number my company has registered via twilio and configured to be a sender.
In the Twilio logs, I see error 63016 message not in template, even though I double-checked every word and spacing to see that my message matches the approved template
some code to help:
def send_message(phone, template_message):
try:
message = twilio_client.messages.create(
body=template_message,
from_=f'whatsapp:{MY_SENDER_NUMBER}',
to=f'whatsapp:{phone}'
)
except TwilioRestException as e:
return False, e.msg
return True, ''
this completes with no error and results in this log line in twilio
From,To,Body,Status,SentDate,ApiVersion,NumSegments,ErrorCode,AccountSid,Sid,Direction,Price,PriceUnit
"whatsapp:+XXXXXXXXXXXX","whatsapp:+XXXXXXXXXXXX","MY MESSAGE THAT MATCHES THE TEMPLATE,
WITH SOME NEWLINES!
AND some characters like '' and ,
",UNDELIVERED,2021-04-11T07:58:32Z,"2010-04-01",1,63016,XXXXXXXXXXXXXXXXXXXXXXXXXXXXx,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx,"
outbound-api",0.0,USD
note: if I open my whatsapp and sends the sender a message, then if I run this code again it will work and I will see that message (as that message does not have to match a template for a 24-hr window).
After help from Twilio support, it was a missing '\n' in the message that I was trying to send, that caused the message not to match the template.
I had the same problem, but was due to just a simple whitespace.

Error when trying to join a channel via API

im using slack to make chat bot so i can create a message center from my ios app to send message from ios app to slack.
getting following response from hitting joinChannel api https://slack.com/api/channels.join
cant get channel ids
{
"provided" : "admin,identify,chat:write:bot",
"ok" : false,
"needed" : "channels:write",
"error" : "missing_scope"
}
As the error message says you need the channels.write scope to use channels.join method.
Just add the missing scope to your access token and it will work.

How do I get twilio 5 digit error code for a failed voice call?

We have a callback url in place that is correctly capturing the failed status of a call.
Our code then fetches from twilio the details of the call by doing the following:
$call = $twilio_client->calls($sid)->fetch();
Within the call details returned there is no 5 digit error code listed, even though the failed status is present.
How do we get the 5 digit error code that caused the failure?
Twilio developer evangelist here.
Thanks to #miknik for the answer, however that is actually a deprecated resource (which is why you can't currently find any documentation on the matter). It's taken me a while to find the answer as I've been chasing down where the notifications have gone.
The Notifications API was deprecated in favour of the Monitor Alerts API. This API can give you all the details about an alert, including the 5 digit code.
The best way to receive these alerts for your application is to set up a webhook in your account console which will send all the parameters about the alert as part of the request.
You can also list your alerts which will allow you to find alerts from a specific resource SID (in your case, a call SID).
Let me know if this helps at all.
Make an authenticated GET request to
/2010-04-01/Accounts/{AccountNumber}/Calls/{CallSid}/Notifications
So in PHP the following will retrieve the notification info for your call
$json = file_get_contents('https://{AccountNumber}:{AuthToken}#api.twilio.com/2010-04-01/Accounts/{AccountNumber}/Calls/{CallSid}/Notifications.json');
Then use this line to get the returned JSON into an associative array
$obj = json_decode($json, true);
Now if all you want is the error code its stored as the following variable
echo $obj[notifications][0][error_code];
However, the full error info is also returned as a URL encoded string. You can access this by first urldecoding it, and then parsing the query string into an array with the following line
parse_str(urldecode($obj[notifications][0][message_text]), $output);
And you can now access the variables within like this
echo $output[Msg]; // Error text for failure eg invalid phone number
echo $output[phonenumber]; // Phone number for failed call
echo $output[ErrorCode]; // 5 digit error code
echo $output[LogLevel];` // Log level of error eg WARN
As far as I know this is not implemented in the PHP helper library, so you have to code for it manually

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

StatusCallback does not work as expected

Overview:
I am working on a VB.NET application that places a call into Twilio, the number is not a test number. I am using the C# library with the code written in VB.Net.
When I use this line of code:
Console.WriteLine(account.SendSmsMessage(Caller, to1, strBody))
I receive a text message on my phone however the post back is never posted to my website. I have included the URL of the site on the account under Messaging > Request URL.
When I reply to the message, Twilio does make a post to my site. From what I understand, a POST should have been made when Twilio was first sent a message from my application, however this is not the case.
When using this code, I do not get any text message and no POST is made.
Console.WriteLine(account.SendMessage(Caller, to1, strBody, PostBackURL))
I have tried SendSMSMessage, I have tried it with the URL on my account and without it,
nothing seems to effect the behavior.
I need the SmsMessageSid at the time the message is sent. From everything I have seen, Twilio does not provide a response other then what is sent to the PostBackURL, I could parse a response for the
SmsMessageSid however since there is no response that is not an option. If I am mistaken on that point that would be great, however it looks like the only way to get a reply is with the post back URL. Thanks for your help with this! Below you will find an excerpt of the code I am working with:
PostBackURL = "http%3A%2F%2F173.111.111.110%3A8001/XMLResponse.aspx"
' Create Twilio REST account object using Twilio account ID and token
account = New Twilio.TwilioRestClient(SID, Token)
message = New Twilio.Message
Try
'WORKS
'Console.WriteLine(account.SendSmsMessage(Caller, to1, strBody))
'DOES NOT WORK
Console.WriteLine(account.SendMessage(Caller, to1, strBody, PostBackURL))
Catch e As Exception
Console.WriteLine("An error occurred: {0}", e.Message)
End Try
Console.WriteLine("Press any key to continue")
Console.ReadKey()
I'm doing something similar with C# and like you, I'm not getting the POST to the callback URL. I don't know why that's not working, but if all you need is the sid when you send the message, you should be able to do this:
message = SendSmsMessage(Caller, to1, strBody))
and message.Sid will give you what you need, assuming no exceptions.

Resources