2016-11-21 69 views
2

我目前正在使用此slackbot軟件包爲Slack構建一個bot。擴展類以創建自定義功能

目前,它無法構建自定義附件,例如附加圖像。

查看源代碼,Question類負責構建交互式問題 - 將其全部捆綁到一個準備發送給Slack的數組中。

我希望使用其中的大部分功能來構建一個可以將image_url添加到數組中的類,但是我從來沒有這樣做過,並且不知道如何執行此操作或從何處開始。

最終,我只是希望能夠使用該包發送消息幷包含圖像附件。

從我可以拼湊,我需要開始是這樣的:

<?php 

namespace //namespace; 

use Mpociot\SlackBot\Question; 

class Attachments extends Question 
{ 
    //code to add image URL goes here 

    /** 
    * there is currently this function in the Question class 
    * that builds the array where I need to add in 
    * 'image_url => 'example.com/image_url' 
    */ 
    public function toArray() 
    { 
     return [ 
      'text' => $this->text, 
      'fallback' => $this->fallback, 
      'callback_id' => $this->callback_id, 
      'actions' => $this->buttons, 
     ]; 
    } 

} 

誰能幫我指出了正確的方向,或者幫助我開始使用它?

+0

您可以在https://github.com/iranianpep/給Slackbot框架出手slackbot。它是專門爲Slack編寫的,可能對您的情況有所幫助 – Ehsan

回答

1

您可以通過使用得到parent類的所有功能:

parent::toArray(); 

在這種情況下,擴展類整體功能將被執行。你總是可以編寫導致像一個變量:

$parent = parent::toArray(); 

,你可以像返回它:

return array (
     'image_url' => 'example.com/image_url', 
) + parent::toArray();