PHP code example of albertcht / notion-ai

1. Go to this page and download the library: Download albertcht/notion-ai library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

albertcht / notion-ai example snippets


$notion = new AlbertCht\NotionAi\NotionAi('token', 'spaceId');

$notion = new AlbertCht\NotionAi\NotionAi('token', 'spaceId', ['timeout' => 120]);

$client = new GuzzleHttp\Client();
$notion->setClient($client);

$notion->sendRequest([
    [
        'type' => $promptType,
        'pageTitle' => $pageTitle,
        'selectedText' => $selectedText,
    ]
]);

// you can set buffer size of stream in the second parameter
$notion->stream(function ($output) {
    echo $output;
    if (ob_get_length()) {
        ob_get_flush();
        flush();
    }
}, 128);
$notion->sendRequest([
    [
        'type' => $promptType,
        'pageTitle' => $pageTitle,
        'selectedText' => $selectedText,
    ]
]);

public function writeWithPrompt(string $promptType, string $selectedText, string $pageTitle = ''): ?string;

public function continueWriting(string $previousContent, string $pageTitle = '', string $restContent = ''): ?string;

public function helpMeEdit(string $prompt, string $selectedText, string $pageTitle = ''): ?string;

public function helpMeWrite(string $prompt, string $previousContent = '', string $pageTitle = '', string $restContent = ''): ?string;

public function helpMeDraft(string $prompt, string $previousContent = '', string $pageTitle = '', string $restContent = ''): ?string;

public function translate(string $text, string $language): ?string;

public function changeTone(string $text, string $tone): ?string;

public function summarize(string $selectedText, string $pageTitle = ''): ?string;

public function improveWriting(string $selectedText, string $pageTitle = ''): ?string;

public function fixSpellingGrammar(string $selectedText, string $pageTitle = ''): ?string;

public function explainThis(string $selectedText, string $pageTitle = ''): ?string;

public function makeLonger(string $selectedText, string $pageTitle = ''): ?string;

public function makeShorter(string $selectedText, string $pageTitle = ''): ?string;

public function findActionItems(string $selectedText, string $pageTitle = ''): ?string;

public function simplifyLanguage(string $selectedText, string $pageTitle = ''): ?string;

public function writeWithTopic(string $topic, string $prompt): ?string;

public function brainstormIdeas(string $prompt): ?string;

public function outline(string $prompt): ?string;

public function socialMediaPost(string $prompt): ?string;

public function creativeStory(string $prompt): ?string;

public function poem(string $prompt): ?string;

public function essay(string $prompt): ?string;

public function meetingAgenda(string $prompt): ?string;

public function pressRelease(string $prompt): ?string;

public function jobDescription(string $prompt): ?string;

public function salesEmail(string $prompt): ?string;

public function recruitingEmail(string $prompt): ?string;

public function prosConsList(string $prompt): ?string;