Discovering the Magic of a Custom LINE Bot for Chat Recaps

Hey there, imagine you're juggling a bunch of lively group chats on LINE, and things get chaotic with messages flying everywhere. What if you had a clever little robot that could swoop in and boil it all down into a neat summary? That's exactly what I've been tinkering with – a bot that scans your group discussions and delivers concise overviews. It's like having a personal note-taker who's always on duty, saving you time and keeping you in the loop without the hassle of scrolling through endless threads.

Why This Bot Changes the Game for Group Communication

Let's face it, group chats can turn into a whirlwind of ideas, plans, and random chit-chat. Whether it's coordinating a team project or catching up with friends, sifting through everything manually is a drag. This bot steps in by analyzing the conversation flow and pulling out the key points. It's especially handy for busy folks who need to jump back in without missing a beat. Plus, it supports requests in different languages, making it versatile for global users.

  • Efficiency Boost: No more endless scrolling – get the gist in seconds.
  • Customization Options: Tailor it to focus on specific topics or time frames.
  • Easy Integration: Hooks right into your existing LINE setup via their developer tools.

Setting It Up: A Step-by-Step Breakdown

Getting this bot up and running is straightforward if you're into a bit of coding. Start by heading over to the LINE Developers Console to create your bot channel. From there, you'll dive into the Messaging API to handle incoming messages. The core idea is to process chat data and generate summaries using natural language processing tricks – think libraries like those from Hugging Face for the heavy lifting.

Once configured, users can trigger the summary with a simple command. For instance, here's how a request might look in the chat:

title: [Learning Document] LINE Bot Group Chat Summary Generator
published: false
date: 2022-12-29 00:00:00 UTC
tags: 
canonical_url: http://www.evanlin.com/linebot-chatgpt/
---

![image-20221230150344227](http://www.evanlin.com/images/2022/image-20221230150344227.png)

# Preface:

Hello everyone, I am Evan Lin, a Senior Technical Promotion Engineer at LINE Taiwan. Some time ago, [OpenAI](https://openai.com) released their well-known GPTv3 NLP Model for everyone to use, and provided a user-friendly interface [ChatGPT](https://chat.openai.com/chat). It has received considerable attention worldwide, and we have seen many developers in the community sharing related development cases.

- [I tried to integrate GPT-3 into a LINE chatbot](https://dev.classmethod.jp/articles/chatgpt-line-chat-bot/)
- https://beta.openai.com/docs/api-reference/completions/create
- https://github.com/isdaviddong/chatGPTLineBot
- [https://github.com/memochou1993/gpt-ai-assistant](https://github.com/memochou1993/gpt-ai-assistant)

But in fact, [ChatGPT](https://chat.openai.com/chat) is not just directly connected to the chatbot, perhaps it can also help us solve many of the pain points of the past. The following article will share how to use [ChatGPT](https://chat.openai.com/chat) to create a chatbot specifically for summarizing group chats for you.

# Pain Points of Problems Solved

Do you all have similar problems? Often joining a group, there are too many messages running around in it, and when you look back, you find that there are already too many unread messages in it. Often you need to go in and slowly chase each message to avoid missing too much (FOMO)?

Because of my work, I have many groups and a lot of messages. I used to think about how to use NLP or AI to help me organize the summary of related content. But there has never been a better result. But since [ChatGPT](https://chat.openai.com/chat) came out of nowhere, this part of the function seems to be achievable, let's try it.

## How to use ChatGPT to summarize group chat messages

- Go to a chat group and press copy to copy the messages you need.
- Paste it into [ChatGPT](https://chat.openai.com/chat) and add `幫我總結` (summarize for me).

幫我用繁體中文總結 (Summarize for me in Traditional Chinese)

[Evan Lin]: 我肚子餓了 . 2022-12-29 13:04:01
[Evan Lin]: 想去吃午餐 . 2022-12-29 13:04:05
[Nijia Lin]: 不知道吃什麼好 . 2022-12-29 13:04:08
[Nijia Lin]: 大家想吃什麼勒? . 2022-12-29 13:04:13
[Evan Lin]: 我去買麥當勞 . 2022-12-29 13:04:18


#### ChatGPT Summary Results

![image-20221230154217442](http://www.evanlin.com/images/2022/image-20221230154217442.png)

# How to build your own group summary chatbot

## Source Code:

#### [https://github.com/kkdai/LINE-Bot-ChatSummarizer](https://github.com/kkdai/LINE-Bot-ChatSummarizer)

## Get a LINE Bot API developer account

- If you want to use LINE Bot, please make sure to register for a LINE developer console account at [https://developers.line.biz/console/](https://developers.line.biz/console/).
- Create a new message channel and get the "Channel Secret" on the "Basic Settings" tab.
- Get the "Channel Access Token" on the "Messiging API" tab.
- Open the LINE OA Manager from the "Basic Settings" tab, and then go to the OA Manager's reply settings. Enable "webhook" there.

## Get OpenAI API Token

- Register an account at https://openai.com/api/.
- Once you have an account, you can find your API Token on the account settings page.
- If you want to use the OpenAI API in development, you can find more information and instructions on the API documentation page.

Please note that the OpenAI API is only open to users who meet certain conditions. You can find more information about the terms of use and restrictions of the API on the API documentation page.

## Deploy on Heroku

- Enter "Channel Secret", "Channel Access Token" and "ChatGPT Access Token".

- Remember your Heroku server ID.

## Set up the basic API in the LINE Bot Dashboard:

- Set up your basic account information, including "Webhook URL" at [https://{YOUR\_HEROKU\_SERVER\_ID}.herokuapp.com/callback](https://%7Byour_heroku_server_id%7D.herokuapp.com/callback).

# Results

- Follow the "How to Install" to perform the relevant deployment process.
- Add the bot to the group chat room. [![img](http://www.evanlin.com/images/2022/chat_1.png)](https://github.com/kkdai/LINE-Bot-ChatSummarizer/blob/master/img/chat_1.png)

- Able to remember the conversations within the group.

![list_all.png](http://www.evanlin.com/images/2022/list_all-20221230151706913.png)

- Directly send the group content summary privately to you.

![sum_all.png](http://www.evanlin.com/images/2022/sum_all-20221230151647428.png)

### Related commands are as follows

- `:gpt xxx`: Directly talk to ChatGPT, you can ask him directly.
- `:list_all`: List the message records of the group (all)
- `:sum_all`: Help you summarize the message.

# Development Process Record (mainly Golang):

The following will explain step by step how to develop such a chatbot:

### How to get the information of the chat group (group) (through Webhook) and store the messages:

First, you need to know that you are in a chat group. So how to get the Group ID and record the relevant messages. Here, I would also like to mention that in the latest news on 2022/12/27, it is no longer possible to obtain the relevant information of the Group ID from LIFF. In other words, in the group, the only way to get the LINE group ID is through Webhook.

<script src="https://gist.github.com/kkdai/f67d3ece464876bfb4c5fcf09a1ad1ca.js"></script>
### Quick Summary:

- **ID of the chat group** ( `event.Source.GroupID` ): Please note that if it is a one-on-one chat directly with the official account. The value here will be empty.
- **How to store data**: This example program is mainly for everyone to have a related feeling, so it uses memory plus map to store it. If you really want to use it online, please remember to use it with a database.

## How to use the ChatGPT API through Golang
<script src="https://gist.github.com/kkdai/7f099ee6613374805292f8b8e9ca1484.js"></script>
### Quick Summary:

- It is recommended to use the package: [github.com/sashabaranov/go-gpt3](https://github.com/sashabaranov/go-gpt3)
- You can slightly adjust the Model selection. But the results of `Davinci001` are really not good.

## How to summarize your chat room messages through the API
<script src="https://gist.github.com/kkdai/cc6a635c495bfefb6fcc35e8271e3216.js"></script>
### Quick Summary:

- Because the call of [ChatGPT](https://chat.openai.com/chat) takes more time, it is better to reply to the user first, and then call to wait for the answer.
- The summary is to add a `幫我總結` (summarize for me) in front of all the text. Remember to enclose it with symbols, and if you want to avoid too many simplified characters, you can add `請用繁體中文` (Please use Traditional Chinese).

## Related technical documents:

- [LINE News: Plans to discontinue providing company internal identifiers of chat rooms to LIFF apps](https://developers.line.biz/en/news/2022/12/27/liff-spec-change/)
- [LINE API: Getting user profiles](https://developers.line.biz/en/docs/android-sdk/managing-users/#get-profile)
- [LINE API: Get group chat member profile](https://developers.line.biz/en/reference/messaging-api/#get-group-member-profile)
- [LINE API: Get group chat summary](https://developers.line.biz/en/reference/messaging-api/#group)

# Future related work

[ChatGPT](https://chat.openai.com/chat) is a very interesting service. This article uses its function to help summarize an article. To help us summarize the chat records of the chat group.

This allows people who haven't followed for a long time to quickly catch up with the topics of everyone's chat.

The code this time is quite simple and easy to understand, and I hope it can be a stepping stone to see more applications from you.

[ChatGPT](https://chat.openai.com/chat) actually has more applications to explore, and I believe that this service can also enable the LINE official account to exert powerful functions.

If you have any suggestions or questions, please feel free to contact us through [the official discussion forum of LINE Developers](https://www.facebook.com/groups/linebot) or [the official account of the LINE developer community](https://lin.ee/qZRsSTG).

After that, the bot processes the recent messages and spits out a tidy recap in Traditional Chinese, highlighting main ideas, decisions, and any action items. It's all about making tech feel approachable and useful in everyday scenarios.

Tips for Enhancing Your Bot Experience

To make it even better, experiment with adding features like sentiment analysis to gauge the group's vibe or integrating with calendars for event reminders. If you're new to this, check out tutorials on Heroku for hosting your bot's backend – it's free for starters and scales nicely. Remember, always test in a small group first to iron out any quirks.

In the end, this kind of tool isn't just about tech wizardry; it's about streamlining how we connect. Give it a shot, and you might wonder how you managed without it!