2016-11-21 46 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();