messagebird / python-rest-api Goto Github PK
View Code? Open in Web Editor NEWThis repository contains the open source Python client for MessageBird's REST API.
License: BSD 2-Clause "Simplified" License
This repository contains the open source Python client for MessageBird's REST API.
License: BSD 2-Clause "Simplified" License
How to reproduce?
ACCESS_KEY = 'live_333aacc22bbbddd'
client = messagebird.Client(ACCESS_KEY)
vmsg = client.voice_message_create('3131611111111, 3131622222222', 'Hello friend.', { 'reference' : 'Foobar' })
The message gets send to the number 3131611111111 but the call raises this exception:
Traceback (most recent call last):
File "voice_message_create.py", line 15, in <module>
vmsg = client.voice_message_create('31630174123, 31624971134', 'Hello sugar.', { 'reference' : 'Foobar' })
File "../messagebird/client.py", line 94, in voice_message_create
return VoiceMessage().load(self.request('voicemessages', 'POST', params))
File "../messagebird/base.py", line 7, in load
setattr(self, name, value)
File "../messagebird/voicemessage.py", line 41, in recipients
value['items'] = [Recipient().load(r) for r in value['items']]
File "../messagebird/base.py", line 5, in load
for name, value in data.items():
AttributeError: 'unicode' object has no attribute 'items'
If you change the order of the recipients to '3131622222222, 3131611111111' it works.
This exception shouldn't be risen.
I'm getting wrong message_id on client.conversation_start
message id is different from the server.
each time client.conversation_start returns same id
python-rest-api/messagebird/client.py
Lines 364 to 366 in bcb9b03
There is an Error
code : 21
description : Channel not found
parameter : channelId
When I trying to send a message to WhatsApp (template), I'm using Live API Key and Correct Channel ID.
Note: I'm able to send message using cURL with normal text. there is no such error for Channel ID.
The response from the whatsapp sandbox when creating a message has variable names with different capitalization than the ConversationMessage object, meaning that the conversation message objects that are returned from client.conversation_read_message and client.conversation_create_message are empty.
Documentation says: "In case of an error, the body of the response includes a json formatted response that tells you exactly what is wrong."
, but once this API raises an ErrorException with json response error codes it also suppress response's HTTP status code, as you can see: https://github.com/messagebird/python-rest-api/blob/master/messagebird/client.py#L58
Hi
Is there a query argument for the /contacts/ endpoint to sort the contacts ascending or descending by createdDatetime?
Thanks,
pyenv install 3.4.10
pipenv install --python 3.4.10
pipenv install messagebird
pipenv run python examples/number_available_list.py --accessKey XXXXXXXXXXXXXXX
An <class 'AttributeError'> exception occurred while :
'Client' object has no attribute 'available_numbers_list'
Hi,
I'm intermittently getting the following error when sending SMS messages using the Python client:
https://app.getsentry.com/share/issue/38393239372e313531303139363139/
The reason for the error appears to be the format the Python code expects back at this point (https://app.getsentry.com/share/issue/38393239372e313531303139363139/):
@recipients.setter
def recipients(self, value):
value['items'] = [Recipient().load(r) for r in value['items']]
self._recipients = value
which differs from what the API returns (I've removed the real number but will happily share privately if that helps):
{
'items': {
'1': {
'recipient': xxxxxxxxxx,
'status': 'sent',
'statusDatetime': '2016-08-18T21:26:06+00:00'
}
},
'totalCount': 1,
'totalDeliveredCount': 0,
'totalDeliveryFailedCount': 0,
'totalSentCount': 1
}
So basically this line appears to expect a list of dictionaries back...
value['items'] = [Recipient().load(r) for r in value['items']]
... but it's getting a dictionary or dictionaries with the key 1
, and the list comprehension here is simply sending through the key which isn't the dictionary expected by load(r)
.
Since this doesn't always happen this seems most likely to be an error with the API, as in I can't see anywhere in the code where it would handle data in this structure received back from the API and for the most part this error doesn't occur when I send text messages. Also the API docs and example suggest items should be a list not a dictionary (https://developers.messagebird.com/docs/messaging#messaging-send).
A possible short-term hack I could try would be to patch the library to sniff the data type first, e.g:
@recipients.setter
def recipients(self, value):
if isinstance(value['items'], dict):
items = value['items']
keys = sorted([int(k) for k in items.keys()])
value['items'] = [Recipient().load(items[k]) for k in keys]
else:
value['items'] = [Recipient().load(r) for r in value['items']]
self._recipients = value
...though if I'm honest I'd really prefer not to have to do this.
I'm using version 1.2.0 of your Python client library.
ok, I found, that it sends messages for non-test accounts. But for what reasons are they used? Thank you
conversation_create_message
example not working with sandbox anymore.
It was working fine on last release of v1.6.0
After pip install, import and initializing the client
Traceback (most recent call last):
File "messagebird.py", line 1, in <module>
import messagebird
File "/home/carlos/Escritorio/projects/twilio/messagebird.py", line 2, in <module>
client = messagebird.Client('YOUR_ACCESS_KEY')
AttributeError: partially initialized module 'messagebird' has no attribute 'Client' (most likely due to a circular import)
Thank you
When looking up a phone number to do preliminary validation, the API can raise a HTTPError instead of ErrorException, as the HTTP status code 400 is not handled in the client.
Raising an ErrorException would be more consistent, as a HTTPError usually indicates networking errors or bad requests, not "phone number seems invalid".
Sample response:
x
Out[91]: requests.exceptions.HTTPError('400 Client Error: Bad Request for url: https://rest.messagebird.com/lookup/1234567890')
x.response.content
Out[92]: b'{"errors":[{"code":21,"description":"Bad request (phone number has unknown format)","parameter":"phone_number"}]}\n'```
It seems like your pip version is not updated.
Calling >>>pip install messagebird installs package version 1.4.1. This is how messagebird/client.py looks like:
class Client(object):
def init(self, access_key, http_client=None):
This is version on git:
class Client(object):
def init(self, access_key, http_client=None, features=[]):
Dear reader,
I'm trying to implement your awesome SMS API into my Python final assignmetn (for higher education semester 1). The deadline is two weeks from now and I've been busy for 2 weeks..
The following guide:
https://developers.messagebird.com/quickstarts/sms/send-sms-python
By copy/pasting your tutorial code and insert my own phone number, I still don't get the program to run. I've managed to do it in Node.JS and those instructions were clear. I ask if you please create the SMS feature locally in Python by following exactly the tutorial please.
Does that work for you then?
I have tried your template and then tried editing to:
import messagebird
client = messagebird.Client('ypt3ryCKm0WnfppAQt3hcd0Yt')
message = client.message_create(
'+31610433256',
{'originator': '+31610433256'},
{'recepient': '+31610433256'},
'Hello World, mijn eerste SMS',
{ 'reference' : 'Foobar' }
)
But I receive in both cases:
code:
send_sms.py : The term 'send_sms.py' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
Can you please help me?
Kind regards,
Leroy Andrade
Hello!
I hope you are doing well!
We are a security research team. Our tool automatically detected a vulnerability in this repository. We want to disclose it responsibly. GitHub has a feature called Private vulnerability reporting, which enables security research to privately disclose a vulnerability. Unfortunately, it is not enabled for this repository.
Can you enable it, so that we can report it?
Thanks in advance!
PS: you can read about how to enable private vulnerability reporting here: https://docs.github.com/en/code-security/security-advisories/repository-security-advisories/configuring-private-vulnerability-reporting-for-a-repository
Running API via python does not work:
[rvdzwet@rvdzwet-asus python-rest-api]$ python examples/balance.py
An error occured while requesting a Balance object:
code : 2
description : Request not allowed (incorrect access_key)
parameter : access_key
Fixed curl request (with same dummy key) goes just fine:
[rvdzwet@rvdzwet-asus ~]$ curl https://rest.messagebird.com/balance -H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM'
{"payment":"prepaid","type":"credits","amount":10.1}
I am following this process using messagebird library.
I am combining message_create.py and message.py.
client = messagebird.Client(ACCESS_KEY)
msg = client.message_create(originator_phonenumber, array of recipient_phonenumber, 'Hello World')
ms = client.message(msg.id)
and I am getting this error:
An error occured while requesting a Message object:
code : 20
description : message not found
parameter : None
@samwierema Please help me on this.
hello, i am currently facing an issue when trying to send messages in arabic with the message bird api. it works perfectly fine with other languages but not arabic.
here's a code snippet:
`
import messagebird
import arabic_reshaper
def send_msg(receiver, expiration_date):
if receiver == NULL:
pass
else:
expiration_date = expiration_date[::-1]
text = f"عزيزي العميل ، ينتهي اشتراكك في XXX غدًا بتاريخ {expiration_date}، لتجديده ، يرجى الاتصال بنا."
reshaped_text = arabic_reshaper.reshape(text)
rev_text = reshaped_text[::-1]
client = messagebird.Client("XXXXXXXXX")
message = client.message_create('XXXXXTest',
f'{str(receiver)}',
rev_text,
{ 'reference' : 'Foobar' }
)
`
i tried using arabic reshaper module and when i print the "rev_text" in the terminal it works perfectly fine, meaning that it is shown the way it is expected
but when i receive the message on my phone, there are no arabic characters what so ever, as if they were deleted entirely, meaning i only receive the expiration date and the "XXX" and nothing else. please view the image below to understand what i mean.
The README.md file says, at the end:
Complete documentation, instructions, and examples are available at: https://www.messagebird.com/developers/python.
However, this link redirects to the generic https://developers.messagebird.com/ page, which is not Python-specific.
Either the link should be updated to point to Python-specific documentation, or it should point to the generic page (so that users aren't confused/frustrated at getting a generic page when they've been led to expect a Python-specific one).
As a developer I want to use the Conversations API through the Messagebird SDK
There is an error when sending a message through Whatsapp. The message comes through and is received on the app, but the response json for
client.conversation_start({ })
instead of it being an error or success is the following.
File "/usr/local/lib/python3.8/site-packages/messagebird/client.py", line 343, in conversation_start return Conversation().load(self.request(uri, 'POST', start_request, CONVERSATION_TYPE)) File "/usr/local/lib/python3.8/site-packages/messagebird/base.py", line 11, in load setattr(self, name, value) File "/usr/local/lib/python3.8/site-packages/messagebird/conversation.py", line 30, in contact self._contact = ConversationContact().load(value) File "/usr/local/lib/python3.8/site-packages/messagebird/base.py", line 11, in load setattr(self, name, value) File "/usr/local/lib/python3.8/site-packages/messagebird/conversation_contact.py", line 23, in customDetails self._customDetails = CustomDetails().load(value) File "/usr/local/lib/python3.8/site-packages/messagebird/base.py", line 9, in load for name, value in list(data.items()):
Channel id, namespace and test phone number as omitted for security but are all correct. The code being is used is:
msg = client.conversation_start({ 'channelId': '####', 'to': '521##########', 'type': MESSAGE_TYPE_HSM, 'content': { 'hsm': { 'namespace': '####', 'templateName': 'verification', 'language': { 'policy': 'deterministic', 'code': 'en' }, 'params': [ {"default": "MessageBird"}, {"default": "123456"} ] } } })
Hi,
I'm trying to implement some text to speech voice message.
I need to detect machine answers to be able to call another phone for notification escalation.
But get status like these with ifMachine set to 'hangup':
calling calling calling ... answered
Second try, I hang up the call manually:
calling calling calling ... answered
So, is there a way to detect both these two scenarios (machine answer and manual hang up) ?
jfr
MessageBird: [Version 2.0.0]
I see that you have implemented RequestValidator
but it's not released yet.
Since, I (and many others) add packages via pip, the latest version we have is v2.0.0. Using that version, I can't migrate request validation from MessageBird-Signature and MessageBird-Request-Timestamp
to MessageBird-Signature-JWT header
.
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.