Share your content with Contentful and Telegram
Tags: contentful, telegram, extensibility, headlesscms
Published: 2024-06-03 11:17:42

Hello and welcome!

What I'm about to present is the final part of my journey with Telegram and Contentful. 
Following my article published on the Contentful Blog (you can read more [here](https://www.contentful.com/blog/telegram-webhooks-bots/)), in this post, I’ll show you how I built a custom app to send messages to your Telegram Channel right from your Contentful entry.

This won't be a technical section, more of a “show and tell”. However, if you are interested in seeing the code, at the end of the article you will find links to the repositories.

---

## **Key Points of the Application**

Let's define what, how, and where our application will operate.

As many of you may already know, the App Framework allows us to customize various parts of the Contentful web interface. In our case, we will modify the configuration screen of the app itself to define some parameters necessary for its overall operation. While the actual app will reside within the sidebar of our entries.

Our application will provide the user with the ability to send content to an external endpoint, leveraging the data from the current entry or completely custom data. The endpoint will then be responsible for retrieving the data and sending it to the associated Telegram channel (this part has been covered on the other article).

---

## **Configuration Screen**

Let's start with the initial configuration. As mentioned earlier, without this, our app cannot function. Why is that? Simply because here, we give the user the ability to define multiple endpoints that our app can then use to send information. 

Each endpoint can define different logics; for example, we can have an endpoint that relies on a Test channel that we can use to send test messages. Another example could be having different channels for different topics, providing us with the flexibility to communicate different information.

Let's see how the initial screen looks:

&nbsp;

![Configuration - Empty Screen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qy52cv8ioxjhveom3g1n.png)

&nbsp;

From here, we can add, modify, or delete our endpoints. The entry form includes the following fields:

- **Name**: name of the endpoint.
- **Url**: URL of our external service.
- **Channel Id**: Telegram channel ID.
- **Channel name**: name of the Telegram channel.

&nbsp;

![Configuration - Form](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/otp8nled9zhztmsw70g8.png)

&nbsp;

Doing so, we obtain a list of endpoints that our app will then utilize:

&nbsp;

![Configuration - Endpoint List](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m9k8y4e3ktr511e9l2qy.png)

&nbsp;

---

## **Sidebar App**

As mentioned earlier, we will be working in a specific location, the sidebar.

This allows our application to be available on every entry of a specific content type (or more than one if desired).

Once the app is installed, to display it in the sidebar, we will need to modify the 'Sidebar' section of our content type:

&nbsp;

![Sidebar - Configuration](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xuislked1drsgk9tgahc.png)

&nbsp;

..and move our 'Telegram Sender' app to the right-hand list, choosing the position, and then saving the content type:

&nbsp;

![Sidebar - Configuration Highlight](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s89qn78b27it9jpun9so.png)

&nbsp;

Now, if we go to any Entry of type Recipe, we will see our application ready to be used:

&nbsp;

![Sidebar - Content Type Entry](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9t2fe98cvzf43mjzujge.png)

&nbsp;

### **How does it work?**

Now that we have configured our app, let's see how it works.

After clicking 'Configure message,' the first crucial step is selecting the endpoint for sending our data:

&nbsp;


![Sidebar - Channel Selection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ofhl4b9d9mgk3sv0lvu.png)

&nbsp;

Once the channel is selected, we will have a form with the following fields:

- Media
- Text message and parse mode
- Link URL and Link name

Let's examine them in detail.

&nbsp;

### **Media**

&nbsp;

![Sidebar - Media Selection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tim6sd2nz2rhm7nqrm22.png)

&nbsp;

This field allows us to select media in different ways.

We can create a new media from scratch or choose one from those already present. These first two options are fixed and interact through the Contentful SDK, displaying the default interface. For example, if we select 'Select existing media,' the application will open a modal with our saved assets:

&nbsp;

![Sidebar - Media Picker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nlqtrf6jzyuh7e6wisfb.png)

&nbsp;

The other entries starting with 'Entry field: ...' are dynamic entries based on the structure of our Content Type. In our example, our recipe, has only one Media-type field named 'Image.' Clicking on this option allows us to directly select the image associated with that field. If the field in the entry is not populated, the option in the select would still be present but disabled:

&nbsp;

![Sidebar - Entry Media Overview](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/50tsfigapjxgt0muo8qs.png)

&nbsp;

### **Text Message and Parse Mode:**

This is where you can configure the text message to send to the channel. Similar to the media field, we have some dynamic fields based on the structure of our Content Type. Within the options, we have fields of type Symbol/Text. In addition to these, we have a 'Custom value' option that allows us to enter free text:

&nbsp;

![Sidebar - Text Picker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1j2etab1yejzqe1girvm.png)

![Sidebar - Text Message](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/86klh6t4kiqfxe8e79v9.png)

&nbsp;

The 'Parse Mode' option is specific to Telegram, indicating the format of the text we are entering. The options are: HTML (Default), Markdown, and MarkdownV2.

&nbsp;

![Sidebar - Parse Mode](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ked6wldoo7grl2n7lgmd.png)

&nbsp;

There are links provided that redirect to the Telegram documentation for more information on these options.

&nbsp;

### **Link URL and Name**

These two optional fields allow you to define a link and a label to include in our message. Again, similar to the text message, we have the option to use fields from the entry or enter custom values:

&nbsp;

![Sidebar - Link Url](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cjyqeawqntfkurbtklj2.png)

&nbsp;

### **Preview and Send CTA**

The application also provides a preview of the message we are about to send. This feature can be useful for users who want to see how the message will appear within the Telegram channel before sending:

&nbsp;

![Sidebar - Message Preview](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6uu32hrouef3esfqrzg6.png)

&nbsp;

When the message is ready, we can click on the 'Send Message' CTA, which will send the data to our external endpoint responsible for delivering the message to our Telegram channel. The implementation of the external service will be very similar to what we saw in the previous article.

---

## **Conclusion**

And with this, our journey through Bots, Webhooks, and custom apps comes to an end.

We've seen how, with simple configurations, we can establish our presence on Telegram and leverage the power of webhooks with just a few lines of code.

Last but not least, thanks to the power of the App Framework, we've been able to explore the creation of a small app that puts into practice everything we've learned in the [previous article](https://www.contentful.com/blog/telegram-webhooks-bots/), all within the Contentful interface.

Below, you can find the links to the repositories used in this series:

- [Webhook endpoint](https://github.com/williamiommi/contentful-webhook-telegram/blob/main/api/telegram/message.js)
- [Telegram Sender App](https://github.com/williamiommi/contentful-app-telegram-sender)