line / line-bot-sdk-python

LINE Messaging API SDK for Python
https://pypi.python.org/pypi/line-bot-sdk
Apache License 2.0
1.91k stars 971 forks source link

How to used ClipboardAction? #610

Closed dalnel closed 6 months ago

dalnel commented 6 months ago

I want add ClipboardAction in Buttons Template ,but it is not work,my code:

from linebot.v3.messaging.models import ClipboardAction
from linebot.models import ButtonsTemplate, MessageAction, TemplateSendMessage, CarouselTemplate,  CarouselColumn, PostbackAction, URIAction

def delet_CarouselTemplate():
    columns=[]
    column_item = ButtonsTemplate(
        title="copy test",
        text="click button to copy text",
        actions=[
            ClipboardAction(
                type="clipboard",
                label="copy",
                clipboardText="copy hellow word"
            )
        ]
    )
    columns.append(column_item)
    return TemplateSendMessage(
        alt_text='ButtonsTemplate',
        template=ButtonsTemplate(columns)
    )
CarouselTemplate = delet_CarouselTemplate()
line_bot_api.reply_message(tk,CarouselTemplate)

I used breakpoints in VS Code to inspect what was happening, and I found out that this action was not even added. So, I checked the linebot.models, and I realized that ClipboardAction is not included there. Did I use the wrong method or did I forget to add it?

image

YrChen1001 commented 6 months ago

I can't use this action either

Yang-33 commented 6 months ago

Hi @YrChen1001, thank you for using line-bot-sdk-python. Please import definition from linebot.v3.messaging.models instead of linebot.models. linebot.models are too old. I'll deprecate them.

Yang-33 commented 6 months ago

https://github.com/line/line-bot-sdk-python/blob/12360f822d966c7790a7f109b04db579107c443e/examples/flask-kitchensink/app.py#L303-L322 shows how to use ButtonsTemplate in linebot.v3.messaging.models, that might help you!