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

Add dumping for keyboard key value. #112

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Beastrock
Copy link

@Beastrock Beastrock commented Jun 18, 2018

Сейчас вк-разработчики добавили апи кнопок для ботов. Там такой формат ключа keyboard - словарь с листами (листами) словарей.

При вызове message.send с ключом keyboard ломалось его значение - условие if isinstance(value, Iterable) and not isinstance(value, STRING_TYPES) выполнялось и для значения keyboard ключа, следовательно, value = u','.join(map(str_type, value)) меняло всю вложенную структуру на ключи словаря keyboard через запятую. Ну а дальше возникала ошибка API - неправильный формат аргументов метода.

Добавил условие в цикл - для таких сложных структур делаем json.dumps(value).

Тестил fix только на send.message, поэтому было бы хорошо посмотреть\потестить как фикс повлияет на другие методы API. Вроде, только в кейборд такой формат данных и всё должно быть 👌 👌 👌

@Beastrock
Copy link
Author

Beastrock commented Jun 18, 2018

А вообще, можно гораздо проще. Сделать дамб самого значения ключа и не исправлять апи 👍

KEYBOARD = { "one_time": False, "buttons": [ [{ "action": { "type": "text", "payload": "{\"button\": \"1\"}", "label": "Red" }, "color": "negative" }, { "action": { "type": "text", "payload": "{\"button\": \"3\"}", "label": "White" }, "color": "default" }] ] }

api_group.messages.send( access_token=stg.GROUP_ACCESS_TOKEN, user_id=user_id, message=message, attachment=attachment, keyboard=keyboard=json.dumps(KEYBOARD) )

или так внутри меняем заэкраннированный payload:
{ "action": { "type": "text", "payload": json.dumps({"button": "3"}), "label": "White" }, "color": "default"

Copy link
Collaborator

@YariKartoshe4ka YariKartoshe4ka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужен ребейз на последний коммит master. Также добавь тесты в tests/test_utils.py (test_stringify и test_stringify_values) для данного случая


if isinstance(value, dict):
value = json.dumps(value)

if isinstance(value, Iterable) and not isinstance(value, STRING_LIKE_TYPES):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if -> elif

@@ -48,8 +48,13 @@ def json_iter_parse(response_text):
def stringify_values(dictionary):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Теперь этот код находится в функции stringify

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

Successfully merging this pull request may close these issues.

5 participants