【问题标题】:navigate on images of a product in a telegram bot在电报机器人中导航产品的图像
【发布时间】:2018-07-08 12:07:18
【问题描述】:

我正在 laravel 中通过 https://github.com/php-telegram-bot/core 开发电报机器人商店。

在这个应用程序中,每个产品都有许多图像,它们的路径存储在数据库中。

现在我希望在发送产品详细信息时,用户可以通过上一个和下一个 内嵌键盘 逐一显示该产品的图像。喜欢这张照片:

为此,将商店中的所有产品显示为 内联查询 并在使用后选择其中一个,在 Chosen inline result Command 上,我得到一个产品 ID 和像这样从数据库中获取第一张图片:

class ChoseninlineresultCommand extends SystemCommand
    {
    public function execute ()
    {
        $chosenInlineResult   = $this->getChosenInlineResult();
        $chosenInlineResultId = $product_id = $chosenInlineResult->getResultId();
        $chat_id              = $chosenInlineResult->getFrom()->getId();

        $product = Product::findOrFail($product_id);

        $picture = $product->images->first();

        $keyboard = KeyboardController::showProductKeyboard($product_id, $chat_id);

        $result = view('show-product', compact('product','picture'))->render();

        Request::sendMessage([
            'chat_id'      => $chat_id,
            'text'         => $result,
            'reply_markup' => $keyboard,
            'parse_mode'   => 'HTML'
        ]);
    }
    }

还有KeyboardControllershowProductKeyboard是这样的:

    static public function showProductKeyboard ($product_id, $user_id)
    {

        $inlineKeyboard = new InlineKeyboard([]);
        $inlineKeyboard->addRow(new InlineKeyboardButton([
            'text'          => ' previous picture ⬅️️',
            'callback_data' => 'prev_pic'
        ]), new InlineKeyboardButton([
            'text'          => '➡️ next picture ',
            'callback_data' => 'next_pic'
        ]));

        return $inlineKeyboard;
    }

最后show-product刀片很简单:

????️ <b>{{$product->title}}</b>

✅ <b>{{str_limit(strip_tags($product->desc), 50)}}</b>

???? <b>{{number_format($product->price)}}</b> dollor

<a href="{{config('app.url').'/upload/'. $picture}}"> Picture</a>

问题是我不知道如何实现我想要的。

【问题讨论】:

    标签: php laravel telegram telegram-bot


    【解决方案1】:

    无法通过回调查询更改商品图片,只能通过editMessageText https://core.telegram.org/bots/api#editmessagetext方法更改文字

    解决方案可以是删除消息并发送带有下一张图片的新消息。 你应该在 callback_data 中设置更多的数据。例如showproduct_&lt;id next product&gt;

    【讨论】:

      猜你喜欢
      • 2017-08-18
      • 1970-01-01
      • 2016-10-18
      • 1970-01-01
      • 2018-02-27
      • 2018-07-22
      • 2020-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多