本文整理汇总了PHP中Longman\TelegramBot\Request::sendPhoto方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::sendPhoto方法的具体用法?PHP Request::sendPhoto怎么用?PHP Request::sendPhoto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Longman\TelegramBot\Request
的用法示例。
在下文中一共展示了Request::sendPhoto方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$command = $message->getCommand();
$text = trim($message->getText(true));
$data = ['chat_id' => $chat_id];
//No point in replying to messages in private chats
if (!$message->getChat()->isPrivateChat()) {
$data['reply_to_message_id'] = $message->getMessageId();
}
if ($command !== 'whois') {
$text = substr($command, 5);
//We need that '-' now, bring it back
if (strpos($text, 'g') === 0) {
$text = str_replace('g', '-', $text);
}
}
if ($text === '') {
$text = 'Provide the id to lookup: /whois <id>';
} else {
$user_id = $text;
$chat = null;
$created_at = null;
$updated_at = null;
$result = null;
if (is_numeric($text)) {
$results = DB::selectChats(true, true, true, null, null, $user_id);
if (!empty($results)) {
$result = reset($results);
}
} else {
$results = DB::selectChats(true, true, true, null, null, null, $text);
if (is_array($results) && count($results) === 1) {
$result = reset($results);
}
}
if (is_array($result)) {
$result['id'] = $result['chat_id'];
$chat = new Chat($result);
$user_id = $result['id'];
$created_at = $result['chat_created_at'];
$updated_at = $result['chat_updated_at'];
$old_id = $result['old_id'];
}
if ($chat !== null) {
if ($chat->isPrivateChat()) {
$text = 'User ID: ' . $user_id . PHP_EOL;
$text .= 'Name: ' . $chat->getFirstName() . ' ' . $chat->getLastName() . PHP_EOL;
$username = $chat->getUsername();
if ($username !== null && $username !== '') {
$text .= 'Username: @' . $username . PHP_EOL;
}
$text .= 'First time seen: ' . $created_at . PHP_EOL;
$text .= 'Last activity: ' . $updated_at . PHP_EOL;
//Code from Whoami command
$limit = 10;
$offset = null;
$response = Request::getUserProfilePhotos(['user_id' => $user_id, 'limit' => $limit, 'offset' => $offset]);
if ($response->isOk()) {
/** @var UserProfilePhotos $user_profile_photos */
$user_profile_photos = $response->getResult();
if ($user_profile_photos->getTotalCount() > 0) {
$photos = $user_profile_photos->getPhotos();
/** @var PhotoSize $photo */
$photo = $photos[0][2];
$file_id = $photo->getFileId();
$data['photo'] = $file_id;
$data['caption'] = $text;
return Request::sendPhoto($data);
}
}
} elseif ($chat->isGroupChat()) {
$text = 'Chat ID: ' . $user_id . (!empty($old_id) ? ' (previously: ' . $old_id . ')' : '') . PHP_EOL;
$text .= 'Type: ' . ucfirst($chat->getType()) . PHP_EOL;
$text .= 'Title: ' . $chat->getTitle() . PHP_EOL;
$text .= 'First time added to group: ' . $created_at . PHP_EOL;
$text .= 'Last activity: ' . $updated_at . PHP_EOL;
}
} elseif (is_array($results) && count($results) > 1) {
$text = 'Multiple chats matched!';
} else {
$text = 'Chat not found!';
}
}
$data['text'] = $text;
return Request::sendMessage($data);
}
示例2: execute
/**
* {@inheritdoc}
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = ['chat_id' => $chat_id, 'caption' => $text];
//Return a random picture from the telegram->getUploadPath().
return Request::sendPhoto($data, $this->ShowRandomImage($this->telegram->getUploadPath()));
}
示例3: execute
/**
* {@inheritdoc}
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = [];
$data['chat_id'] = $chat_id;
$data['caption'] = $text;
//return Request::sendPhoto($data, $this->telegram->getUploadPath().'/'.'image.jpg');
return Request::sendPhoto($data, $this->ShowRandomImage($this->telegram->getUploadPath()));
}
示例4: execute
public function execute()
{
$update = $this->getUpdate();
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = array();
$data['chat_id'] = $chat_id;
$data['caption'] = $text;
//$result = Request::sendDocument($data,'structure.sql');
//$result = Request::sendSticker($data, $this->telegram->getUploadPath().'/'.'image.jpg');
$result = Request::sendPhoto($data, $this->telegram->getUploadPath() . '/' . 'image.jpg');
return $result;
}
示例5: execute
public function execute()
{
$update = $this->getUpdate();
$message = $this->getMessage();
$user_id = $message->getFrom()->getId();
$chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$text = $message->getText(true);
//send chat action
Request::sendChatAction(['chat_id' => $chat_id, 'action' => 'typing']);
$caption = 'Your Id: ' . $message->getFrom()->getId();
$caption .= "\n" . 'Name: ' . $message->getFrom()->getFirstName() . ' ' . $message->getFrom()->getLastName();
$caption .= "\n" . 'Username: ' . $message->getFrom()->getUsername();
//Fetch user profile photo
$limit = 10;
$offset = null;
$ServerResponse = Request::getUserProfilePhotos(['user_id' => $user_id, 'limit' => $limit, 'offset' => $offset]);
//Check if the request isOK
if ($ServerResponse->isOk()) {
$UserProfilePhoto = $ServerResponse->getResult();
$totalcount = $UserProfilePhoto->getTotalCount();
} else {
$totalcount = 0;
}
$data = [];
$data['chat_id'] = $chat_id;
$data['reply_to_message_id'] = $message_id;
if ($totalcount > 0) {
$photos = $UserProfilePhoto->getPhotos();
//I pick the latest photo with the hight definition
$photo = $photos[0][2];
$file_id = $photo->getFileId();
$data['photo'] = $file_id;
$data['caption'] = $caption;
$result = Request::sendPhoto($data);
//Download the image pictures
//Download after send message response to speedup response
$file_id = $photo->getFileId();
$ServerResponse = Request::getFile(['file_id' => $file_id]);
if ($ServerResponse->isOk()) {
Request::downloadFile($ServerResponse->getResult());
}
} else {
//No Photo just send text
$data['text'] = $caption;
$result = Request::sendMessage($data);
}
return $result;
}
示例6: execute
/**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
$message = $this->getMessage();
$from = $message->getFrom();
$user_id = $from->getId();
$chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$data = ['chat_id' => $chat_id, 'reply_to_message_id' => $message_id];
//Send chat action
Request::sendChatAction(['chat_id' => $chat_id, 'action' => 'typing']);
$caption = sprintf('Your Id: %d' . PHP_EOL . 'Name: %s %s' . PHP_EOL . 'Username: %s', $user_id, $from->getFirstName(), $from->getLastName(), $from->getUsername());
//Fetch user profile photo
$limit = 10;
$offset = null;
$response = Request::getUserProfilePhotos(['user_id' => $user_id, 'limit' => $limit, 'offset' => $offset]);
if ($response->isOk()) {
/** @var UserProfilePhotos $user_profile_photos */
$user_profile_photos = $response->getResult();
if ($user_profile_photos->getTotalCount() > 0) {
$photos = $user_profile_photos->getPhotos();
/** @var PhotoSize $photo */
$photo = $photos[0][2];
$file_id = $photo->getFileId();
$data['photo'] = $file_id;
$data['caption'] = $caption;
$result = Request::sendPhoto($data);
//Download the photo after send message response to speedup response
$response2 = Request::getFile(['file_id' => $file_id]);
if ($response2->isOk()) {
/** @var File $photo_file */
$photo_file = $response2->getResult();
Request::downloadFile($photo_file);
}
return $result;
}
}
//No Photo just send text
$data['text'] = $caption;
return Request::sendMessage($data);
}
示例7: execute
//.........这里部分代码省略.........
$notes['name'] = $text;
$text = '';
// no break
// no break
case 1:
if ($text === '') {
$notes['state'] = 1;
$this->conversation->update();
$data['text'] = 'Type your surname:';
$result = Request::sendMessage($data);
break;
}
$notes['surname'] = $text;
$text = '';
// no break
// no break
case 2:
if ($text === '' || !is_numeric($text)) {
$notes['state'] = 2;
$this->conversation->update();
$data['text'] = 'Type your age:';
if ($text !== '') {
$data['text'] = 'Type your age, must be a number:';
}
$result = Request::sendMessage($data);
break;
}
$notes['age'] = $text;
$text = '';
// no break
// no break
case 3:
if ($text === '' || !in_array($text, ['M', 'F'], true)) {
$notes['state'] = 3;
$this->conversation->update();
$data['reply_markup'] = (new Keyboard(['M', 'F']))->setResizeKeyboard(true)->setOneTimeKeyboard(true)->setSelective(true);
$data['text'] = 'Select your gender:';
if ($text !== '') {
$data['text'] = 'Select your gender, choose a keyboard option:';
}
$result = Request::sendMessage($data);
break;
}
$notes['gender'] = $text;
// no break
// no break
case 4:
if ($message->getLocation() === null) {
$notes['state'] = 4;
$this->conversation->update();
$data['reply_markup'] = (new Keyboard((new KeyboardButton('Share Location'))->setRequestLocation(true)))->setOneTimeKeyboard(true)->setResizeKeyboard(true)->setSelective(true);
$data['text'] = 'Share your location:';
$result = Request::sendMessage($data);
break;
}
$notes['longitude'] = $message->getLocation()->getLongitude();
$notes['latitude'] = $message->getLocation()->getLatitude();
// no break
// no break
case 5:
if ($message->getPhoto() === null) {
$notes['state'] = 5;
$this->conversation->update();
$data['text'] = 'Insert your picture:';
$result = Request::sendMessage($data);
break;
}
/** @var PhotoSize $photo */
$photo = $message->getPhoto()[0];
$notes['photo_id'] = $photo->getFileId();
// no break
// no break
case 6:
if ($message->getContact() === null) {
$notes['state'] = 6;
$this->conversation->update();
$data['reply_markup'] = (new Keyboard((new KeyboardButton('Share Contact'))->setRequestContact(true)))->setOneTimeKeyboard(true)->setResizeKeyboard(true)->setSelective(true);
$data['text'] = 'Share your contact information:';
$result = Request::sendMessage($data);
break;
}
$notes['phone_number'] = $message->getContact()->getPhoneNumber();
// no break
// no break
case 7:
$this->conversation->update();
$out_text = '/Survey result:' . PHP_EOL;
unset($notes['state']);
foreach ($notes as $k => $v) {
$out_text .= PHP_EOL . ucfirst($k) . ': ' . $v;
}
$data['photo'] = $notes['photo_id'];
$data['reply_markup'] = Keyboard::remove(['selective' => true]);
$data['caption'] = $out_text;
$this->conversation->stop();
$result = Request::sendPhoto($data);
break;
}
return $result;
}
示例8: execute
//.........这里部分代码省略.........
// no break
case 1:
if (empty($text)) {
$this->conversation->notes['state'] = 1;
$this->conversation->update();
$data['text'] = 'Type your surname:';
$result = Request::sendMessage($data);
break;
}
$this->conversation->notes['surname'] = $text;
++$state;
$text = '';
// no break
// no break
case 2:
if (empty($text) || !is_numeric($text)) {
$this->conversation->notes['state'] = 2;
$this->conversation->update();
$data['text'] = 'Type your age:';
if (!empty($text) && !is_numeric($text)) {
$data['text'] = 'Type your age, must be a number';
}
$result = Request::sendMessage($data);
break;
}
$this->conversation->notes['age'] = $text;
$text = '';
// no break
// no break
case 3:
if (empty($text) || !($text == 'M' || $text == 'F')) {
$this->conversation->notes['state'] = 3;
$this->conversation->update();
$keyboard = [['M', 'F']];
$reply_keyboard_markup = new ReplyKeyboardMarkup(['keyboard' => $keyboard, 'resize_keyboard' => true, 'one_time_keyboard' => true, 'selective' => true]);
$data['reply_markup'] = $reply_keyboard_markup;
$data['text'] = 'Select your gender:';
if (!empty($text) && !($text == 'M' || $text == 'F')) {
$data['text'] = 'Select your gender, choose a keyboard option:';
}
$result = Request::sendMessage($data);
break;
}
$this->conversation->notes['gender'] = $text;
$text = '';
// no break
// no break
case 4:
if (is_null($message->getLocation())) {
$this->conversation->notes['state'] = 4;
$this->conversation->update();
$data['reply_markup'] = new ReplyKeyboardMarkup(['keyboard' => [[['text' => 'Share Location', 'request_location' => true]]], 'resize_keyboard' => true, 'one_time_keyboard' => true, 'selective' => true]);
$data['text'] = 'Share your location:';
$result = Request::sendMessage($data);
break;
}
$this->conversation->notes['longitude'] = $message->getLocation()->getLongitude();
$this->conversation->notes['latitude'] = $message->getLocation()->getLatitude();
// no break
// no break
case 5:
if (is_null($message->getPhoto())) {
$this->conversation->notes['state'] = 5;
$this->conversation->update();
$data['text'] = 'Insert your picture:';
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
$result = Request::sendMessage($data);
break;
}
$this->conversation->notes['photo_id'] = $message->getPhoto()[0]->getFileId();
// no break
// no break
case 6:
if (is_null($message->getContact())) {
$this->conversation->notes['state'] = 6;
$this->conversation->update();
$data['text'] = 'Share your contact information:';
$data['reply_markup'] = new ReplyKeyboardMarkup(['keyboard' => [[['text' => 'Share Contact', 'request_contact' => true]]], 'resize_keyboard' => true, 'one_time_keyboard' => true, 'selective' => true]);
$result = Request::sendMessage($data);
break;
}
$this->conversation->notes['phone_number'] = $message->getContact()->getPhoneNumber();
// no break
// no break
case 7:
$this->conversation->update();
$out_text = '/Survey result:' . "\n";
unset($this->conversation->notes['state']);
foreach ($this->conversation->notes as $k => $v) {
$out_text .= "\n" . ucfirst($k) . ': ' . $v;
}
$data['photo'] = $this->conversation->notes['photo_id'];
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
$data['caption'] = $out_text;
$this->conversation->stop();
$result = Request::sendPhoto($data);
break;
}
return $result;
}