How to create a command “Select a group” in a telegram bot? - php

I'm using Laravel 8, irazasyed/telegram-bot-sdk.
I created an inline "Select Group" button.
public function handle()
{
$inlineLayout = [
[
Keyboard::inlineButton(['text' => 'Choose a group', 'callback_data' => 'data']),
]
];
$reply_markup = Keyboard::make([
'inline_keyboard' => $inlineLayout,
'resize_keyboard' => true,
'one_time_keyboard' => true,
]);
$this->replyWithMessage(['text' => 'Click on the button to select a group.', 'reply_markup' => $reply_markup]);
}
How to hang an event on this button so that you can select a group in the chat?

It turned out that everything is simple.
It is necessary to add the url parameter:
$inlineLayout = [
[
Keyboard::inlineButton(['text' => 'Choose a group', 'callback_data' => 'data', 'url' => 'https://t.me/all2all_bot?startgroup=c']),
]
];

Related

How to use multiple select on yii kartik widget select2 and ajax

i'm trying to use the Kartik Select2 Widget for my Yii2 project.
I'll use the Ajax Loading and everithing works find, but if i set the multiple option it gives me this error.
PHP Warning – yii\base\ErrorException array_combine(): Both parameters
should have an equal number of elements
This error is in Select2.php on this line
$this->data = $multiple ? array_combine((array)$key, (array)$val) : [$key => $val];
i think it's because the data attribute is missing, but if i add data attribute ajax doesn't work properly.
This is my view:
$form->field($model, 'lista_art')->widget(Select2::classname(), [
'initValueText' => "", // set the initial display text
//'data' => '',
'options' => ['placeholder' => 'Select a color ...',
//'multiple' =>true, // error here
],
'pluginOptions' => [
'tags' => true,
'tokenSeparators' => [',', ' '],
'allowClear' => true,
'minimumInputLength' => 3,
'language' => [
'errorLoading' => new JsExpression("function () { return 'Waiting for results...'; }"),
],
'ajax' => [
'url' => \yii\helpers\Url::to(['lista-articoli']),
'dataType' => 'json',
'data' => new JsExpression('function(params) { return {q:params.term}; }')
],
'escapeMarkup' => new JsExpression('function (markup) { console.log(markup);return markup; }'),
'templateResult' => new JsExpression('function(lista_art) { return lista_art.art_modello; }'),
'templateSelection' => new JsExpression('function (lista_art) { return lista_art.art_modello; }'),
],
]);
Also tried to insert multiple option inside 'pluginOptions' array but doesnt work.
Is it possible to use multiple option with Ajax Loading?
P.s. I've check my developer toolbar and the response is correct, and gives me what i've expected.
You forgot to set data attribute
Sample how to use kartik select 2 with model and active form
$model->keywords = [1, 2]; // NOTE THIS IS AN ARRAY of keys
$form->field($model, 'keywords')->widget(Select2::className(), [
'pluginOptions' => [
'tags' => true,
'multiple' =>true,
],
'data' => [1=>'keyword1', 2=>'keyword2', 3=>'keyword3'],
])
Update
Try to set up data as empty array like
'data' => []

TYPO3 How to add Create new button on TCA?

I would like to build a slider (Own Content Element). So on the backend i would like to have a section with multiple records. What do i mean? By clicking the "Create new" i would like to have an image selection and rich text selection.
Something like that.
How can i achieve this?
So far i have:
TCA/Overrides/tt_content.php
which gives me the rich editor and the image selection in backend, but not grouped.
$GLOBALS['TCA']['tt_content']['types']['my_slider'] = array( 'showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;general,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.headers;headers,bodytext,assets;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.media,
',
'columnsOverrides' => [
'bodytext' => [
'config' => [
'enableRichtext' => true,
'richtextConfiguration' => 'default'
]
]
]
);
tt_content.typosript
tt_content {
my_slider < lib.contentElement
my_slider {
templateRootPaths.10 = {$Private}Templates/
templateName = Slider.html
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = assets
as = images
}
}
}
}
Slider.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<h1>{data.header}</h1>
<p>{data.bodytext}</p>
<f:for each="{images}" as="image">
<f:image image="{image}" alt="{file.properties.alt}" cropVariant="desktop"/>
{image.description}
</f:for>
<f:debug>{data}</f:debug>
</html>
Now with the current code i get the results in frontend. One Text and one Image. But how can i get it as group after configured it on the backend?
You need add new field to the sys_file_reference TCA:
Configuration/TCA/Overrides/sys_file_reference.php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'sys_file_reference',
[
'tx_myext_description' => [
'label' => 'My field description',
'config' => [
'type' => 'text',
'cols' => '80',
'rows' => '15',
'enableRichtext' => true,
'richtextConfiguration' => 'default'
]
],
]
);
ext_tables.sql
CREATE TABLE sys_file_reference (
tx_myext_description mediumtext,
);
Remember to add new field into database (using database compare tool in install tool).
Then use it in TCA of your new slider:
Configuration/TCA/Overrides/tt_content.php
$GLOBALS['TCA']['tt_content']['types']['my_slider'] = [
'showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;general,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.headers;headers,bodytext,assets;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.media,
',
'columnsOverrides' => [
'bodytext' => [
'config' => [
'enableRichtext' => true,
'richtextConfiguration' => 'default'
]
],
'assets' => [
'config' => [
'overrideChildTca' => [
'types' => [
0 => ['showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][0]['showitem'].',tx_myext_description'],
\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT]['showitem'].',tx_myext_description'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE]['showitem'].',tx_myext_description'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO]['showitem'].',tx_myext_description'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO]['showitem'].',tx_myext_description'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION]['showitem'].',tx_myext_description'
],
],
],
],
],
],
];
And then your Fluid template may look like that:
Slider.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<h1>{data.header}</h1>
<p>{data.bodytext}</p>
<f:for each="{images}" as="image">
<f:image image="{image}" alt="{file.properties.alt}" cropVariant="desktop"/>
{image.properties.tx_myext_description -> f:format.html()}
</f:for>
</html>

TYPO3 how to add virtual column to the TCA?

how can I add an virtual column to the TCA (TYPO3 8)? I have in a 1:n table with data and I want to display the count of the data in the backend to current element.
I need something like this:
$fields = [
'counts7d' => [
'exclude' => false,
'label' => 'last 7 days',
'config' => [
'type' => 'none',
'procFunc' => '\Namespace\MyClass->MyMethod',
'readOnly' => true,
'params' => [
'period => '7d'
]
]
],
'counts30d' => [
'exclude' => false,
'label' => 'last 30 days',
'config' => [
'type' => 'none',
'procFunc' => '\Namespace\MyClass->MyMethod',
'readOnly' => true,
'params' => [
'period => '30d'
]
]
],
];
pseudo function:
public function myMethod($element, $params){
$sql = "SELECT count(*) FROM TABLE WHERE pid=$element[uid] and date > $params[period]";
return sql_count…
}
The field should only be informative for the backend users.
Does anyone have an idea?
Thanks
Oliver
The TCA field type user is exactly what you are looking for:
'counts7d' => [
'exclude' => false,
'label' => 'last 7 days',
'config' => [
'type' => 'user',
'userFunc' => \Namespace\MyClass::class . '->MyMethod',
'parameters' => [
'period => '7d',
],
],
],
The TCA field type none is exactly what you are looking for. Type none is the only type that does not necessarily need a database field. To manipulate it you can use userFunc which allow you to use custom php function.

How to add additional info into php array

I use this php code:
public function checkout(&$order, &$response)
{
$settings = Settings::get($order->seller_id);
$readon= 'maksājums';
$readon= $order->id;
$order->custom([
'payment_details' => [
'bank_name' => [ 'label' => $this->_->_('Bank Name'), 'value' => $settings->bank_name ],
'account_owner' => [ 'label' => $this->_->_('Account Owner'), 'value' => $settings->account_owner ],
//'bic' => [ 'label' => $this->_->_('BIC/SWIFT'), 'value' => $settings->bic ],
'iban' => ['label' => $this->_->_('IBAN'), 'value' => $settings->iban ],
'reason' => [ 'label' => $this->_->_('Reason for Payment'), 'value' => $readon],
],
]);
$response = [];
$response['redirect'] = $this->meta('manual_url');
return Payment::STATUS_OK;
}
Problem is that I want to add additional text on value readon. Right now $readon show only order number, but I want that it display text like "Please make payment for Order No.$order->id"
Just concatenate the string with what you need. Like this,
$readon= "Please make payment for Order No. ".$order->id;

Yii2 ListView custom data-attribute based on currend DP model

I need to set custom data-attribute to the ListView elements. As example I try to get current DataProvider model id. But I still view error "htmlspecialchars() expects parameter 1 to be string, object given". Please check my code and halp me - how I should get this ID?
<?= ListView::widget([
'dataProvider' => $photoProvider,
'id' => 'photo-list',
'itemView' => '_photoListItem',
'viewParams' => [
'fullView' => true,
],
'options' => [
'tag' => 'ul',
'class' => 'list-view'
],
'itemOptions' => [
'tag' => 'li',
'class' => 'item',
'data' =>[
'test' => function ($model, $key, $index, $widget) {
return Html::encode($model->id);
}
]
],
'pager' => [
'class' => ScrollPager::className(),
'container' => '#photo-list',
'item' => '.item',
'triggerText' => '<div class="btn more">Load More</div>',
'noneLeftText' => '',
'triggerOffset' => 2,
'negativeMargin' => 200
],
'layout' => "{items}\n{pager}",
]);
?>
This is not possible in the ListView, according to the doc:
'data' => [
'test' => function ($model, $key, $index, $widget) {
return Html::encode($model->id);
}
]
You cannot use a function here. Only static values are allowed.
Alternatively, you can provide those attributes in tags of your _photoListItem view file.

Categories