Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SendAudio from file path does not work #65

Open
dany-hub opened this issue Feb 18, 2025 · 1 comment
Open

SendAudio from file path does not work #65

dany-hub opened this issue Feb 18, 2025 · 1 comment

Comments

@dany-hub
Copy link

dany-hub commented Feb 18, 2025

I urgently need a support. Can anyone help me to reach out how to send audio files directly from a file path to telegram?
I was trying it more times but couldn't find the right way. I always got an error: invalid file HTTP URL specified: URL host is empty.

I would really appreciate your response!

Thanks in advance!

@dany-hub
Copy link
Author

I found a solution for it.
I have changed the following code in TelegramBase.php

I have just added continue; in the foreach loop see in the code below.

public function initializeParams(array $params): array
    {
        $is_resource = false;
        $multipart    = [];

        if (empty($params)) {
            return [];
        }

        //Reformat data array in multipart way if it contains a resource
        $attachments = ['photo', 'sticker', 'audio', 'document', 'video', 'voice', 'animation', 'video_note', 'thumb'];
        foreach ($params as $key => $item) {
            if ($key === 'media') {
                // Magical media input helper.
                $item = $this->mediaInputHelper($item, $is_resource, $multipart);
            } else if (in_array($key, $attachments, true) && file_exists($item)) {
                $file = fopen($item, 'rb');
                $is_resource |= is_resource($file);
                $multipart[] = ['name' => $key, 'contents' => $file];
                continue; // I have added this and it worked for me
            }


            $multipart[]  = ['name' => $key, 'contents' => $item];
        }
        if ($is_resource) {

            return ['multipart' => $multipart];
        }

        return ['form_params' => $params];
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant