Skip to content

Instantly share code, notes, and snippets.

@igamov
Created September 12, 2019 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igamov/52336c2e808e1710dc0bf324ed3b5efc to your computer and use it in GitHub Desktop.
Save igamov/52336c2e808e1710dc0bf324ed3b5efc to your computer and use it in GitHub Desktop.
with photo
<?php
$modtelegram = $modx->getService('modtelegram');
$chat_id = $modx->getOption('chat_id');
$site_url = $modx->getOption('site_url');
$formName = $modx->getOption('formName', $formit->config, 'form-'.$modx->resource->get('id'));
$values = $hook->getValues();
$send_photo = false;
switch ($formName){
case 'footer_form':
$txt = [
"Телефон" => $values['footer__form_phone'],
];
break;
case 'main_form':
if(is_array($values['main__form_departure'])){
$main__form_departure = implode(",",$values['main__form_departure']);
}else{
$main__form_departure = $values['main__form_departure'];
}
if(is_array($values['main__form_feedback'])){
$main__form_feedback = implode(",",$values['main__form_feedback']);
}else{
$main__form_feedback = $values['main__form_feedback'];
}
$txt = [
"Предмет продажи" => $values['main__form_item'],
"Марка, модель" => $values['main__form_model'],
"Срок эксплуатации" => $values['main__form_term'],
"Состояние" => $values['main__form_state'],
"Пожелания по цене" => $values['main__form_price'],
"ФИО" => $values['main__form_name'],
"Телефон" => $values['main__form_phone'],
"Описание" => $values['main__form_text'],
"Нужен ли выезд специалиста" => $main__form_departure,
"Куда отправить цену" => $main__form_feedback,
];
$send_photo = true;
$photo_url = $values['file'];
break;
case 'callback_modal':
$txt = [
"ФИО" => $values['callback__modal_name'],
"Телефон" => $values['callback__modal_phone'],
];
break;
case 'order_modal':
$txt = [
"ФИО" => $values['order__modal_name'],
"Телефон" => $values['order__modal_phone'],
"Детали заказа" => $values["order__modal_title"].' по цене '. $values['order__modal_price'].' руб.',
];
break;
case 'header_form':
$txt = [
"Телефон" => $values['header__form_phone'],
"Предмет продажи" => $values['header__form_item'],
"Описание" => $values['header__form_text'],
];
$send_photo = true;
$photo_url = $values['headerfile'];
break;
}
if (!empty($txt)){
foreach($txt as $key => $value){
$text .= "<b>".$key."</b>: ".$value."\n";
}
$modtelegram->telegramSendMessage([
'chat_id' => $chat_id,
'text' => $text,
]);
if($send_photo && !empty($photo_url)){
$photo_url = explode(',', $photo_url);
foreach($photo_url as $url){
$modtelegram->telegramSendPhoto(array(
'chat_id' => $chat_id,
'from_path' => MODX_BASE_PATH . $url,
));
}
}
return true;
}else{
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment