Posted on Leave a comment

Create WebViewer App in Xcode

WebViewer is a powerful JavaScript-based PDF viewing and document editing library developed by PDFTron Systems Inc. It allows developers to integrate a comprehensive set of PDF functionalities into web applications, making it possible to view, annotate, fill forms, and manipulate PDF documents directly within a web browser.

With WebViewer, developers can build custom PDF solutions tailored to their specific needs. It provides a flexible API that enables deep customization and integration with other web technologies. WebViewer is compatible with various platforms and browsers, including desktop and mobile devices, making it accessible to a wide user base.

WebViewer is widely used by organizations in industries such as finance, legal, healthcare, and education, where PDF documents are a common format for sharing and processing information. It provides a reliable and secure solution for handling PDF files within web applications, empowering users with powerful document management capabilities.

To create a WebView app in Xcode, you can follow the steps below:

Step 1: Open Xcode and create a new project.

  • Launch Xcode and select “Create a new Xcode project.”
  • Choose “App” under the “iOS” section.
  • Select the “Single View App” template and click “Next.”

Step 2: Configure the project settings.

  • Provide a product name for your app, such as “WebViewApp.”
  • Choose the desired organization identifier and set the language to Swift.
  • Select the location to save your project and click “Create.”

Step 3: Design the user interface.

  • Open the Main.storyboard file in the project navigator.
  • Delete the existing view controller scene by selecting it and pressing the Delete key.
  • Drag and drop a new “View Controller” from the Object Library onto the canvas.
  • Select the newly added view controller and go to Editor -> Embed In -> Navigation Controller.

Step 4: Add a WebView to the view controller.

  • Drag and drop a “Web View” from the Object Library onto the canvas.
  • Resize and position the web view to fit the view controller’s bounds.
  • Connect the web view to an outlet in the view controller by selecting the web view, opening the Assistant Editor, and creating an outlet using the “+” button in the view controller’s code.

Step 5: Implement WebView functionality.

  • Open the ViewController.swift file.
  • Import the WebKit framework by adding import WebKit at the top of the file.
  • Create a property for the web view in the view controller class:
@IBOutlet weak var webView: WKWebView!
  • In the viewDidLoad() method, load a web page in the web view:
override func viewDidLoad() {
    super.viewDidLoad()
    
    let url = URL(string: "https://www.example.com")!
    let request = URLRequest(url: url)
    webView.load(request)
}

Step 6: Build and run the app.

  • Connect your iOS device or choose a simulator from the Xcode toolbar.
  • Click the “Build and Run” button (or press Command + R) to build and run the app.
  • Xcode will deploy the app to the selected device or simulator, and you should see your web page loaded in the app’s WebView.

That’s it! You have created a basic WebView app in Xcode using Swift. Feel free to customize the app further, add navigation controls, handle user interactions, or integrate additional features as needed.

Posted on Leave a comment

How to get post view count in WordPress?

In WordPress, the term “post view count” refers to the number of times a specific post or page has been viewed by visitors on your website. It is a metric used to measure the popularity or engagement of a particular piece of content.

Post view count is typically tracked and displayed using plugins or tracking tools specifically designed for WordPress. These plugins integrate with your website and keep a record of the number of times a post or page has been accessed.

To get the post view count in WordPress, you can use a combination of WordPress functions and plugins. Here are two methods you can try:

Method 1: Using a Plugin (such as “Post Views Counter”):

  1. Install and activate the “Post Views Counter” plugin from the WordPress Plugin Directory.
  2. Once activated, the plugin will automatically start tracking the view count for your posts.
  3. To display the view count on your posts, you can use a shortcode provided by the plugin. Edit your post or page and add the shortcode [post-views] to the desired location. This will display the view count when the post is viewed.

Method 2: Manual Implementation:

  1. Open your theme’s functions.php file for editing. You can find this file in your WordPress theme’s directory.
  2. Add the following one of functions code below to the functions.php file:
function get_post_view_count($post_id) {
    $count_key = 'post_views_count';
    $count = get_post_meta($post_id, $count_key, true);
    if ($count == '') {
        delete_post_meta($post_id, $count_key);
        add_post_meta($post_id, $count_key, '0');
        return "0";
    }
    return $count;
}

function set_post_view_count($post_id) {
    $count_key = 'post_views_count';
    $count = get_post_meta($post_id, $count_key, true);
    if ($count == '') {
        $count = 0;
        delete_post_meta($post_id, $count_key);
        add_post_meta($post_id, $count_key, '0');
    } else {
        $count++;
        update_post_meta($post_id, $count_key, $count);
    }
}

// Add the following code where you want to display the view count, e.g., single.php, content.php, etc.
$post_id = get_the_ID();
set_post_view_count($post_id);
$view_count = get_post_view_count($post_id);
echo 'Post Views: ' . $view_count;
  1. Save the functions.php file and upload it back to your server.
  2. The code will update the view count whenever a post is viewed, and you can display the view count using the provided echo statement.

Note: If you’re not comfortable editing theme files directly, you can use a child theme or a custom plugin to add the code instead.

Remember to backup your theme files or create a child theme before making any changes to avoid losing your modifications in case of future theme updates.

Posted on Leave a comment

How to build website for Google Adsense?

What is Google Adsense?

Google AdSense is an advertising program offered by Google that allows website owners or publishers to monetize their online content. It provides a way for website owners to display relevant advertisements on their websites and earn revenue when visitors interact with those ads.

With Google AdSense, publishers can place ad units on their websites, and Google uses its advanced algorithms to analyze the content of the webpages and display ads that are relevant to the visitors’ interests. The ads are created and managed by advertisers who participate in Google’s advertising network.

When a visitor clicks on an ad displayed through AdSense, the website owner earns a portion of the revenue generated by that click. This revenue is typically shared between the publisher and Google, with the publisher receiving a percentage of the ad revenue.

AdSense offers various ad formats, including text ads, display ads, video ads, and mobile ads, allowing publishers to choose the type of ads that best fit their website’s layout and audience.

To participate in Google AdSense, website owners need to apply for an AdSense account and comply with Google’s program policies. Once approved, they can generate ad code from their AdSense account and insert it into their webpages. Google handles the ad serving, targeting, and tracking of the ads, while publishers can monitor their earnings and performance through the AdSense dashboard.

Overall, Google AdSense provides a straightforward and accessible way for website owners to monetize their online content by leveraging the vast advertising network and technology infrastructure of Google.

How to build a website to support Google Adsense to earn money?

To build a website for Google AdSense, you’ll need to follow these general steps:

  1. Choose a Niche: Decide on the topic or niche for your website. Selecting a niche that aligns with your interests or expertise can help you create high-quality content and attract a relevant audience.
  2. Register a Domain: Choose and register a domain name for your website. Make sure it is memorable, easy to spell, and relevant to your niche.
  3. Set Up Web Hosting: Sign up for a reliable web hosting service that suits your needs. Consider factors such as cost, uptime, customer support, and website performance.
  4. Install a Content Management System (CMS): Select a CMS that enables you to manage and publish content easily. Popular options include WordPress, Drupal, and Joomla. WordPress is commonly recommended due to its user-friendly interface and extensive plugin support.
  5. Customize Your Website: Install a suitable theme or template for your CMS and customize it to reflect your brand. Ensure the design is visually appealing, user-friendly, and optimized for mobile devices.
  6. Create High-Quality Content: Start creating valuable and engaging content related to your chosen niche. Focus on providing useful information, solving problems, and offering unique insights to attract and retain visitors.
  7. Set Up Google AdSense Account: Apply for a Google AdSense account at https://www.google.com/adsense/. Follow the guidelines and policies provided by Google while creating your account.
  8. Ad Placement and Optimization: Once your AdSense account is approved, log in to your account and generate ad codes. Place the ad codes strategically on your website to maximize visibility without overwhelming the user experience. Experiment with different ad sizes and formats to find the best-performing options.
  9. Drive Traffic to Your Website: Implement effective digital marketing strategies to increase traffic to your website. Consider techniques like search engine optimization (SEO), social media marketing, email marketing, and content promotion.
  10. Monitor and Optimize: Regularly monitor your website’s performance and AdSense reports to analyze the effectiveness of your ads. Optimize your ad placements, experiment with different ad formats, and refine your content strategy to improve your earnings.

Remember to comply with Google AdSense policies, which include not clicking on your ads, not placing ads on prohibited content, and following guidelines related to ad placement and user experience.

Building a successful AdSense website takes time, effort, and continuous improvement. Stay updated with industry trends, test new strategies, and focus on providing value to your visitors to maximize your earnings.

Posted on Leave a comment

Display Bootstrap Carousel with WordPress

What is Carousel?

The carousel is a slideshow for cycling through a series of content, built with CSS 3D transforms and a bit of JavaScript. It works with a series of images, text, or custom markup. It also includes support for previous/next controls and indicators.

Read more document about carousel here: https://getbootstrap.com/docs/5.2/components/carousel/

Note: Bootstrap Carousel will start its work from two contents so you need to create at least two WordPress post to testing your work. If you want your slideshow to slide only your specific post or Featured Post, please see here how to create Feature Post or Sticky Post, please see here how to get your WordPress sticky post.

Here! we have already implemented Bootstrap Carousel and WordPress as below:

<?php
$last_posts = new WP_Query( array(
    'post_type'           => 'post',
    'posts_per_page'      => 4,
    'post_status'  => 'publish',
    'post__not_in' => get_option('sticky_posts'),
    'tax_query' => array(
        array(
            'taxonomy' => 'post_tag',
            'field'    => 'name',
            'terms'    => 'Featured',
        ),
    ),
    'orderby'             => 'rand',
    'order'               => 'desc'
) );
?>
<section class="py-5 bg-light border-bottom border-top">
    <div class="container-fluid px-3">
    <div class="row row-cols-2">
     <?php
        if ( is_active_sidebar( 'suostei_featured_ad' ) ) :
            $cols_first = "col-lg-8";
            $cols_second = "col-lg-4";
        else:
            $cols_first = "col-lg-12";
            $cols_second = "col-lg-12";
        endif;
     ?>
     <div class="<?php echo $cols_first;?> col-md-12 col-sm-12 col-12">
         <div id="quickButton" class="carousel slide" data-bs-ride="carousel">
            <div class="carousel-indicators">
              <button type="button" data-bs-target="#quickButton" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
              <button type="button" data-bs-target="#quickButton" data-bs-slide-to="1" aria-label="Slide 2"></button>
              <button type="button" data-bs-target="#quickButton" data-bs-slide-to="2" aria-label="Slide 3"></button>
              <button type="button" data-bs-target="#quickButton" data-bs-slide-to="3" aria-label="Slide 4"></button>
            </div>
                <div class="carousel-inner h-100">
                  <?php 
                    if ($last_posts->have_posts()): 
                        $last_posts->the_post();
                            if (has_post_thumbnail()):
                                $post_thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $last_posts->ID ),'full');
                            else:
                                $post_thumbnail = array(suostei_theme_uri.'/assets/noimage.jpg','');
                            endif;
                    ?>
                    <div class="carousel-item active">
                        <div class="row g-0 overflow-hidden flex-md-row mb-1 h-100 w-100 position-relative">
                        <div class="card card-cover h-100 overflow-hidden text-bg-dark" style="background-image: url('<?php echo $post_thumbnail[0];?>');">
                            <div class="col p-4 d-flex flex-column position-static text-shadow-1 bg-dark bg-opacity-50">
                                <h4 class="mb-0 lh-base card-text text-center p-3 display-6"><a class="link-info" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                                <hr/>
                                <p class="card-text text-center mb-auto overflow-hidden p-5 pb-lg-5 pt-lg-4 px-lg-5 h-100 carousel-caption-size"><?php echo suostei_excerpt();?></p>
                                <hr/>
                                <div class="d-flex justify-content-between d-block">
                                    <p class="p-0">
                                       <?php 
                                            $categories = get_the_category($last_posts->ID);
                                            if ( ! empty( $categories ) ) {
                                                echo '<a class="link-info" href="'.esc_attr(esc_url(get_category_link($categories[0]->term_id))).'">'.esc_html( $categories[0]->name ).'</a>';	
                                            }
                                        ?>
                                    </p>
                                    <div class="mb-1 text-info text-end p-0">
                                        <time datetime="<?php echo get_the_date('c'); ?>" itemprop="datePublished">
                                            <?php 
                                                echo get_the_date($last_posts->ID);
                                            ?>
                                        </time>
                                    </div>
                                    <p class="p-0">
                                        <a class="float-end link-info" onClick="window.location.href='<?php the_permalink();?>'" type="button" class="btn btn-primary btn-lg px-4 me-md-2"><i class="fas fa-book-open-reader"></i> <?php echo readmore;?></a>
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>
                    </div>
                <?php endif;?>
                <?php while ($last_posts->have_posts()): 
                    $last_posts->the_post();
                        if (has_post_thumbnail()):
                            $post_thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $last_posts->ID ),'full');
                         else:
                            $post_thumbnail = array(suostei_theme_uri.'/assets/noimage.jpg','');
                         endif;
                ?>
                <div class="carousel-item">
                    <div class="row g-0 overflow-hidden flex-md-row mb-1 h-100 w-100 position-relative">
                        <div class="card card-cover h-100 overflow-hidden text-bg-dark" style="background-image: url('<?php echo $post_thumbnail[0];?>');">
                            <div class="col p-4 d-flex flex-column position-static text-shadow-1 bg-dark bg-opacity-50">
                                <h4 class="mb-0 lh-base card-text text-center p-3 display-6"><a class="link-info" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                                <hr/>
                                <p class="card-text text-center mb-auto overflow-hidden p-5 pb-lg-5 pt-lg-4 px-lg-5 h-100 carousel-caption-size"><?php echo suostei_excerpt();?></p>
                                <hr/>
                                <div class="d-flex justify-content-between d-block">
                                    <p class="p-0">
                                       <?php 
                                            $categories = get_the_category($last_posts->ID);
                                            if ( ! empty( $categories ) ) {
                                                echo '<a class="link-info" href="'.esc_attr(esc_url(get_category_link($categories[0]->term_id))).'">'.esc_html( $categories[0]->name ).'</a>';	
                                            }
                                        ?>
                                    </p>
                                    <div class="mb-1 text-info text-end p-0">
                                        <time datetime="<?php echo get_the_date('c'); ?>" itemprop="datePublished">
                                            <?php 
                                                echo get_the_date($last_posts->ID);
                                            ?>
                                        </time>
                                    </div>
                                    <p class="p-0">
                                        <a class="float-end link-info" onClick="window.location.href='<?php the_permalink();?>'" type="button" class="btn btn-primary btn-lg px-4 me-md-2"><i class="fas fa-book-open-reader"></i> <?php echo readmore;?></a>
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <?php endwhile;?>
                </div>
                <button class="carousel-control-prev" type="button" data-bs-target="#quickButton" data-bs-slide="prev">
                  <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                  <span class="visually-hidden">Previous</span>
                </button>
                <button class="carousel-control-next" type="button" data-bs-target="#quickButton" data-bs-slide="next">
                  <span class="carousel-control-next-icon" aria-hidden="true"></span>
                  <span class="visually-hidden">Next</span>
                </button>
            </div>
         </div>

     <div class="<?php echo $cols_second;?> col-md-12 col-sm-12 col-12">
         <div class="d-flex justify-content-center">
            <?php do_action('_featured_ads');?>
        </div>
     </div>
 </div>
    </div>
</section>

Please remember that the example code above is working fine with Bootstrap 5.2.2 and WordPress 6.2. Enjoy!

Posted on Leave a comment

Create Feature Post in WordPress

The first thing you should know is that Featured Post has not been available in WordPress for a long time. But we can still create it ourselves by writing query from our tags or categories names.

  1. You just create a post as simple as you can.
  2. Create tag name as “Featured” then add into your recently post.
  3. Implement some codes to call it or just copy the code below:
<?php
$last_posts = new WP_Query( array(
    'post_type'           => 'post',
    'posts_per_page'      => 1,
    'post_status'  => 'publish',
    'post__not_in' => get_option('sticky_posts'),
    'tax_query' => array(
        array(
            'taxonomy' => 'post_tag',
            'field'    => 'name',
            'terms'    => 'Featured',
        ),
    ),
    'orderby'             => 'rand',
    'order'               => 'desc'
) );
if($last_posts->have_posts()):
    $last_posts->the_post();
    //display your code loop here
endif;
?>

That’s it. If you like this post, please give us some thumbs up.

Posted on Leave a comment

Get sticky post – WordPress

Sticky Post is a method used to capture any post, put it in a convenient place for visitors to see every time they visit the site.

Sticky Post has been used since the old WordPress version until now. It is useful and easy to capture the attention of website visitors.

For web developers using WordPress and PHP forms, here is an easy example to implement Sticky Post. Please follow or copy the code below.

<?php
$sticky = get_option('sticky_posts');
if (!empty($sticky)){
    echo '<section class="py-5 text-center container">';
    echo '<div class="row py-lg-5">';
    rsort($sticky);
    $args = array(
        'posts_per_page' => 1,
        'post_status'  => 'publish',
        'post__in' => $sticky,
        'orderby' => 'rand',
        'order'  => 'desc'
    );
    $sticky_post =  new WP_Query($args);
    if ($sticky_post->have_posts()) {
         $sticky_post->the_post();
        ?>
        <div class="col-lg-6 col-md-8 mx-auto">
            <h1 class="fw-light display-6 lh-base"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
            <p class="lead text-muted">
                <?php echo the_excerpt();?>
            </p>
            <p>
              <a href="<?php the_permalink(); ?>" class="btn btn-primary my-2"><i class="fas fa-book-open-reader"></i></a>
              <a href="#more" class="btn btn-secondary my-2"><i class="fas fa-list-alt"></i></a>
            </p>
        </div>
        <?php
    }
    echo '</div>';
    echo '</section>';
}
?>

What you need to see just a few lines below:

$sticky = get_option('sticky_posts');
if (!empty($sticky)){
    echo '<section class="py-5 text-center container">';
    echo '<div class="row py-lg-5">';
    rsort($sticky);
    $args = array(
        'posts_per_page' => 1,
        'post_status'  => 'publish',
        'post__in' => $sticky,
        'orderby' => 'rand',
        'order'  => 'desc'
    );
}

And one more step is to modify your post as Sticky content in your wordpress post dashboard. It is just very simple by only tick on the “Make the post sticky”.

Enjoy!

Posted on Leave a comment

Get posts by category id – wordpress

If you want to get posts from WordPress through Category Id, there are many ways to do so. Visit the WordPress tutorial page to learn more. But here we will show you how easy one by following the example code below:

<div class="container">
<?php
$categories = get_the_category();
$category_id = $categories[0]->term_id;
echo '<h2 class="pb-2 border-bottom">'.$categories[0]->name.'</h2>';
echo '<div class="row row-cols-1 row-cols-lg-1 align-items-stretch py-5">';
$last_posts = new WP_Query( array(
    'post_type'           => 'post',
    'category__in'  => $category_id,
    'post_status'  => 'publish',
    'posts_per_page'      => 12,
    //'orderby'             => 'name',
    'order'               => 'desc'
) );
if($last_posts->have_posts()):?>
<div class="list-group w-auto">
<?php
while ($last_posts->have_posts()):
    $last_posts->the_post();
     if (has_post_thumbnail()):
        $post_thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $last_posts->ID ),'full');
     else:
        $post_thumbnail = array(suostei_theme_uri.'/assets/noimage.jpg','');
     endif;
    ?>
        <div class="d-flex gap-2 w-100 justify-content-between mb-3">
            <div>
              <h4 class="mb-3 text-primary"><a class="link-info" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
              
              <p class="mb-2 text-small"><?php echo gen_string_tiny(suostei_excerpt());?></p>
              <small class="text-nowrap">
                  <time datetime="<?php echo get_the_date('c'); ?>" itemprop="datePublished"><?php echo get_the_date($last_posts->ID); ?></time>
                  <!--<time datetime="<?php echo get_the_date('c'); ?>" itemprop="datePublished"><?php echo get_the_date(); ?></time>--> 
                  <span class="float-end">
                      
                      <?php 
                        $categories = get_the_category($last_posts->ID);
                        if ( ! empty( $categories ) ) {
                           echo '<a href="'.esc_attr(esc_url(get_category_link($categories[0]->term_id))).'">'.esc_html( $categories[0]->name ).'</a>';		
                        }
                      ?>

                  </span>
              </small>
            </div>
        </div>
    <hr/>
    <?php 
    endwhile;
    ?>
</div>
    <div class="col-lg-12 mb-1 mt-3 pt-3">
       <?php do_action('post_pagination');?>
    </div>
    <?php
    endif;
    echo '</div>';
    ?>
</div>


Please notice that, you need to change some variable that are using here by replace with your desire. The best part you need to see is look like below:

<?php
$categories = get_the_category();
$category_id = $categories[0]->term_id;
$last_posts = new WP_Query( array(
    'post_type'           => 'post',
    'category__in'  => $category_id,
    'post_status'  => 'publish',
    'posts_per_page'      => 12,
    //'orderby'             => 'name',
    'order'               => 'desc'
) );
?>

That’s it! this code is working fine for wordpress 4.5 and above.

Posted on Leave a comment

Using VB.net to get Telegram Contact from Group

To get Telegram contacts from a group using VB.NET, you can utilize the Telegram.Bot library, which provides a wrapper around the Telegram Bot API. Here’s an example of how you can achieve this:

1. Install the Telegram.Bot package via NuGet in your VB.NET project.

2. Import the necessary namespaces in your code file:

Imports Telegram.Bot
Imports Telegram.Bot.Args
Imports Telegram.Bot.Types
Imports Telegram.Bot.Types.Enums

3. Set up the Telegram Bot client and authenticate with your bot token:

Dim botToken As String = "YOUR_BOT_TOKEN"
Dim botClient As New TelegramBotClient(botToken)

4. Create an event handler for the OnMessage event to receive messages from the group:

AddHandler botClient.OnMessage, AddressOf OnMessageReceived

5. Implement the event handler to process incoming messages:

Private Sub OnMessageReceived(sender As Object, e As MessageEventArgs)
    Dim message As Message = e.Message

    If message.Type = MessageType.Text Then
        ' Process text messages
        Dim chatId As Long = message.Chat.Id
        Dim senderName As String = message.From.Username
        Dim messageText As String = message.Text

        ' Check if the message is from the group
        If message.Chat.Type = ChatType.Group Then
            ' Access the list of group members
            Dim groupChat As Chat = CType(message.Chat, GroupChat)
            Dim members As User() = groupChat.ChatMembers.ToArray()

            ' Process the members' information
            For Each member As User In members
                Dim memberId As Integer = member.Id
                Dim memberUsername As String = member.Username
                Dim memberFirstName As String = member.FirstName
                Dim memberLastName As String = member.LastName

                ' Do something with the member information
                ' For example, add it to a list or store it in a database
            Next
        End If
    End If
End Sub

6. Start the bot client to begin receiving messages:

botClient.StartReceiving()

Remember to replace "YOUR_BOT_TOKEN" with your actual bot token obtained from the BotFather on Telegram. You also need to adapt the code to store or process the retrieved member information as per your requirements.

Please note that the example assumes you already have a bot created on Telegram and added it to the desired group.

Posted on Leave a comment

Get Telegram ChatID by Telegram Bot using VB.net

To get the Telegram User ID using VB.NET, you can make use of the Telegram Bot API. Follow the steps below to accomplish this:

  1. Create a new Telegram bot by contacting the BotFather on Telegram. The BotFather will provide you with an API token for your bot.
  2. Add the Telegram.Bot NuGet package to your VB.NET project. Right-click on your project in Visual Studio, select “Manage NuGet Packages,” search for “Telegram.Bot,” and install it.
  3. Import the required namespaces in your code file:
 Public Sub GetChatIDJson()
        ' Telegram bot token
        Dim botToken As String = Bot_ApiToken

        ' Make HTTP request to get updates
        Dim apiUrl As String = $"https://api.telegram.org/bot{botToken}/getUpdates"
        Dim request As HttpWebRequest = DirectCast(WebRequest.Create(apiUrl), HttpWebRequest)
        Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)

        ' Read response stream
        Using reader As New StreamReader(response.GetResponseStream())
            Dim jsonResponse As String = reader.ReadToEnd()

            'Parse JSON response
            Dim parsedResponse As JObject = JObject.Parse(jsonResponse)
            Dim resultArray As JArray = DirectCast(parsedResponse("result"), JArray)

            'Iterate over updates
            For Each update As JObject In resultArray
                Dim chatId As Long = update("message")("chat")("id").ToObject(Of Long)()
                Console.WriteLine("Chat ID: " & chatId)
                'UserChatID = chatId
            Next

        End Using

        Console.ReadLine()
    End Sub

Remember to replace “YOUR_BOT_TOKEN” with the actual token obtained from the BotFather.

Posted on Leave a comment

Use Telegram Bot to get User detail VB.net

To use a Telegram bot to get user account details in VB.NET, you need to utilize the Telegram Bot API and establish a connection with your bot. Here’s an example of how you can achieve this:

  1. First, you need to install the Telegram.Bot package using the NuGet package manager in Visual Studio. Right-click on your project, select “Manage NuGet Packages,” search for “Telegram.Bot,” and install it.
  2. Import the necessary namespaces in your VB.NET code:
Imports Telegram.Bot
Imports Telegram.Bot.Args
Imports Telegram.Bot.Types

Module Module1
    Dim botToken As String = "YourBotToken"
    Dim botClient As TelegramBotClient

    Sub Main()
        botClient = New TelegramBotClient(botToken)
        AddHandler botClient.OnMessage, AddressOf Bot_OnMessage
        botClient.StartReceiving()

        Console.WriteLine("Bot started. Press any key to exit.")
        Console.ReadKey()

        botClient.StopReceiving()
    End Sub

    Private Sub Bot_OnMessage(sender As Object, e As MessageEventArgs)
        Dim message As Message = e.Message

        If message.Type = MessageType.Text Then
            Dim chatId As Long = message.Chat.Id

            Dim firstName As String = message.From.FirstName
            Dim lastName As String = message.From.LastName
            Dim username As String = message.From.Username

            Dim reply As String = $"First Name: {firstName}{vbCrLf}" &
                                  $"Last Name: {lastName}{vbCrLf}" &
                                  $"Username: {username}{vbCrLf}"

            botClient.SendTextMessageAsync(chatId, reply)
        End If
    End Sub
End Module

Finally, run your application and send a message to your bot on Telegram. The bot should reply with the user account details.

Don’t forget to replace your own "BotToken" with the actual token for your Telegram bot.