Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Direct Messages API #29

Open
zhombie opened this issue Nov 20, 2019 · 6 comments
Open

Direct Messages API #29

zhombie opened this issue Nov 20, 2019 · 6 comments

Comments

@zhombie
Copy link

zhombie commented Nov 20, 2019

Is it possible to work with direct messages API?

@odrling
Copy link
Owner

odrling commented Nov 21, 2019

Hello !
Yes, but it doesn't look nice right now. Direct Messages API uses JSON and the only way to do it currently is to prepare the data and send it as the _json parameter in the request.

That should work since it is actually in the tests but it doesn't look really nice:

message = {
'event': {
'type': "message_create",
'message_create': {
'target': {'recipient_id': user.id},
'message_data': {
'text': "test %d" % time.time(),
'quick_reply': {
'type': "options",
'options': [
{'label': "Hello",
'description': "Hello",
'metadata': "foo"},
{'label': "World",
'description': "World",
'metadata': "bar"}
]
}
}
}
}
}
await oauth1_client.api.direct_messages.events.new.post(_json=message)

I have to think about another way to work with these endpoints because clearly peony doesn't work well with json requests ^^"

@zhombie
Copy link
Author

zhombie commented Nov 23, 2019

thank u for your response & lib.

that's why i have asked this question, i couldn't find mention about sending data as json. but the main thing that it works)

@zhombie
Copy link
Author

zhombie commented Nov 23, 2019

u can close the issue, the answer satisfies my needs. but if u want to implement direct messages handler, u can just leave issue open as notification)

@zhombie
Copy link
Author

zhombie commented Dec 2, 2019

@odrling hello, again. what about uploading media? it returns an exception "Could not authenticate you.", even if i run with code from documentation.

@odrling
Copy link
Owner

odrling commented Dec 10, 2019

Oh sorry I missed this message.
Picture uploads should still work I see that the tests are still running fine after all this time.
tweet

@odrling
Copy link
Owner

odrling commented Dec 10, 2019

Oh I see one difference with the documentation, I don't think that should change anything but I didn't put the media_id in a list like it is in the documentation.

await oauth1_client.api.statuses.update.post(status="",
media_ids=media.media_id)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants