質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
LINE Messaging API

LINE Messaging APIは、メッセージの送信・返信ができるAPIです。Web APIを経由しアプリケーションサーバとLINEのAPIでやり取りが可能。複数のメッセージタイプや分かりやすいAPIリファレンスを持ち、グループチャットにも対応しています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

0回答

2212閲覧

GitHubのline-bot-sdk-python-masterでflex-massage.pyを利用したいのですが書き方がわかりません。。。

m0t0

総合スコア13

LINE Messaging API

LINE Messaging APIは、メッセージの送信・返信ができるAPIです。Web APIを経由しアプリケーションサーバとLINEのAPIでやり取りが可能。複数のメッセージタイプや分かりやすいAPIリファレンスを持ち、グループチャットにも対応しています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2018/11/02 12:49

編集2018/11/02 12:52

前提・実現したいこと

linebotでflex_messageを使ってbotを作りたい!!
pythonでlinebotを作っています。GitHubのlinebot-sdkの中のflex_message.pyを利用したいのですが、”contents=”の後をどう書けばいいかわかりません。Josonを書けばいいのでしょうか?
下にcodeを載せます。

ここに質問の内容を詳しく書いてください。

発生している問題・エラーメッセージ

from __future__ import unicode_literals from abc import ABCMeta from future.utils import with_metaclass from .actions import get_action from .base import Base from .send_messages import SendMessage class FlexSendMessage(SendMessage): """FlexSendMessage. https://developers.line.me/en/docs/messaging-api/reference/#flex-message Flex Messages are messages with a customizable layout. You can customize the layout freely by combining multiple elements. """ def __init__(self, alt_text=None, contents=None, **kwargs): """__init__ method. :param str alt_text: Alternative text :param contents: Flex Message container object :type contents: :py:class:`linebot.models.flex_message.FlexContainer` :param kwargs: """ super(FlexSendMessage, self).__init__(**kwargs) self.type = 'flex' self.alt_text = alt_text self.contents = contents self.contents = self.get_or_new_from_json_dict_with_types( contents, { 'bubble': BubbleContainer, 'carousel': CarouselContainer } ) class FlexContainer(with_metaclass(ABCMeta, Base)): """FlexContainer. https://developers.line.me/en/docs/messaging-api/reference/#container A container is the top-level structure of a Flex Message. """ def __init__(self, **kwargs): """__init__ method. :param kwargs: """ super(FlexContainer, self).__init__(**kwargs) self.type = None class BubbleContainer(FlexContainer): """BubbleContainer. https://developers.line.me/en/docs/messaging-api/reference/#bubble-container This is a container that contains one message bubble. It can contain four blocks: header, hero, body, and footer. """ def __init__(self, direction=None, header=None, hero=None, body=None, footer=None, styles=None, **kwargs): """__init__ method. :param str direction: Text directionality and the order of components in horizontal boxes in the container :param header: Header block :type header: :py:class:`linebot.models.flex_message.BoxComponent` :param hero: Hero block :type hero: :py:class:`linebot.models.flex_message.ImageComponent` :param body: Body block :type body: :py:class:`linebot.models.flex_message.BoxComponent` :param footer: Footer block :type footer: :py:class:`linebot.models.flex_message.BoxComponent` :param styles: Style of each block :type styles: :py:class:`linebot.models.flex_message.BubbleStyle` :param kwargs: """ super(BubbleContainer, self).__init__(**kwargs) self.type = 'bubble' self.direction = direction self.header = self.get_or_new_from_json_dict(header, BoxComponent) self.hero = self.get_or_new_from_json_dict(hero, ImageComponent) self.body = self.get_or_new_from_json_dict(body, BoxComponent) self.footer = self.get_or_new_from_json_dict(footer, BoxComponent) self.styles = self.get_or_new_from_json_dict(styles, BubbleStyle) class BubbleStyle(with_metaclass(ABCMeta, Base)): """BubbleStyle. https://developers.line.me/en/docs/messaging-api/reference/#objects-for-the-block-style """ def __init__(self, header=None, hero=None, body=None, footer=None, **kwargs): """__init__ method. :param header: Style of the header block :type header: :py:class:`linebot.models.flex_message.BlockStyle` :param hero: Style of the hero block :type hero: :py:class:`linebot.models.flex_message.BlockStyle` :param body: Style of the body block :type body: :py:class:`linebot.models.flex_message.BlockStyle` :param footer: Style of the footer block :type footer: :py:class:`linebot.models.flex_message.BlockStyle` :param kwargs: """ super(BubbleStyle, self).__init__(**kwargs) self.header = self.get_or_new_from_json_dict(header, BlockStyle) self.hero = self.get_or_new_from_json_dict(hero, BlockStyle) self.body = self.get_or_new_from_json_dict(body, BlockStyle) self.footer = self.get_or_new_from_json_dict(footer, BlockStyle) class BlockStyle(with_metaclass(ABCMeta, Base)): """BlockStyle. https://developers.line.me/en/docs/messaging-api/reference/#objects-for-the-block-style """ def __init__(self, background_color=None, separator=None, separator_color=None, **kwargs): """__init__ method. :param str background_color: Background color of the block. Use a hexadecimal color code :param bool separator: True to place a separator above the block True will be ignored for the first block in a container because you cannot place a separator above the first block. The default value is False :param str separator_color: Color of the separator. Use a hexadecimal color code :param kwargs: """ super(BlockStyle, self).__init__(**kwargs) self.background_color = background_color self.separator = separator self.separator_color = separator_color class CarouselContainer(FlexContainer): """CarouselContainer. https://developers.line.me/en/docs/messaging-api/reference/#carousel-container This is a container that contains multiple bubble containers, or message bubbles. The bubbles will be shown in order by scrolling horizontally. """ def __init__(self, contents=None, **kwargs): """__init__ method. :param contents: Array of bubble containers :type contents: list[T <= :py:class:`linebot.models.flex_message.BubbleContainer`] :param kwargs: """ super(CarouselContainer, self).__init__(**kwargs) self.type = 'carousel' new_contents = [] if contents: for it in contents: new_contents.append(self.get_or_new_from_json_dict( it, BubbleContainer )) self.contents = new_contents class FlexComponent(with_metaclass(ABCMeta, Base)): """FlexComponent. https://developers.line.me/en/docs/messaging-api/reference/#component Components are objects that compose a Flex Message container. """ def __init__(self, **kwargs): """__init__ method. :param kwargs: """ super(FlexComponent, self).__init__(**kwargs) self.type = None   ………… …… …(略)

該当のソースコード

python

試したこと

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問