Wechat notice, every day to his girlfriend to send good morning, love words, poetry, weather information, etc
preface
A few days ago when browsing GitHub found a message notification information push to micro channel small tools, also tried to use, configuration is very simple, very convenient to use, very curious to study, I looked at the source found is also very simple ~😛, to tell the truth is more curious how to do micro channel notification 🤓
Although previously done nail nail news notice, but NAIL NAIL I also go to work with, daily use rarely, to say that communication tools in China or wechat, laugh 😑, so, the first tool to receive information notice is best wechat, know all understand ~
Later, ACCORDING to the logic of this function, I thought that with the ability of this message notification, I could customize any content to be pushed to wechat, and found that things became interesting ~
Remember to read an article before is through the mailbox every day to send local love words to his girlfriend operation, mailbox which micro channel effect is good ah, not 😎
Don’t say much directly open the whole, their own every day to send good morning to his girlfriend and local love words of the tool, you can also be a warm man every day ~
Train of thought
Next we will do two main things:
-
The first thing: message notification to wechat capability tool
-
Second thing: message content retrieval and data processing
I have investigated the message notification capability. Other schemes have more or less limitations and deficiencies, so it is appropriate to adopt the scheme of the above tools
To obtain message content, one is to use it quickly through open API, and the other is to obtain it by writing crawler script. Considering the cost of technology and time, scheme 1 is given priority at present, and Scheme 2 can be used as an expansion capability
Message notification tool analysis
wechaty
Documents: wechaty
Wechaty can achieve almost all the functions and capabilities of wechat. When you have a small wechat, you can completely hand it over to wechaty, and then design various capabilities through the code. The playability is completely up to you
Automatic reply, group add, timing push, reply, AI interface capabilities and so on…
The hard condition is that wechaty requires a token provided by wechaty to obtain permissions. There are two methods
- Method 1: Contact relevant personnel to purchase
- Method two: participate in the developer program, contribute to the project and be accepted, free of charge
Related documents: github.com/juzibot/Wel…
If you have added some big guys’ wechat groups, you should have come into contact with the ability to automatically pull groups, automatic reply, automatic daily broadcast of the robot
Dingding, Feishu, enterprise wechat
These three tools are positioned as enterprise-level applications. The advantage of enterprise-level applications is that they are highly customizable. There are many API interfaces and permissions provided by the authorities.
Existing problems:
The real situation of Social apps in China is that, excluding the use of enterprises and organizations, wechat comes first for individuals, regardless of message notification or other capabilities. However, the contradiction is that personal wechat has many limitations and almost does not provide such API development capabilities. Of course, if you can accept Studs or feishu or enterprise wechat, there is no such problem.
New ideas:
As a product of wechat, enterprise wechat has some natural advantages: wechat supports the acceptance of enterprise wechat messages in wechat
Around this ability, we can also achieve the corresponding functional requirements. First of all, we pay attention to the enterprise wechat we created in wechat, and then allow the enterprise wechat to accept messages in wechat.
It’s easy for an individual to create an enterprise wechat, just provide a mobile phone number
Nail nail and fly book use robot notification
summary
If conditions permit, wechaty will be preferred, and if conditions do not permit, enterprise wechat + wechat can be adopted as the second best.
To prepare
1. Registered enterprises
Use the computer to open the official website of enterprise wechat and register an enterprise. Have mobile phone number can register, need not business license! No business license! No business license!
2. Create an application
After successful registration, click “Manage Enterprise” to enter the management interface, choose “Application Management” → “Self-build” → “Create Application”
Fill in the application name at will, and select the company name in the visible range.
After the application is created, access the application details page to obtain the application ID(AgentiD) and application Secret(Secret).
3. Obtain the enterprise ID
Go to the Bottom of the My Enterprise page to obtain the enterprise ID.
4. Push messages to wechat
Enter “my enterprise” → “wechat plug-in”, pull down to scan the TWO-DIMENSIONAL code, after paying attention to you can receive the push message.
Note: If the interface request is normal, the enterprise wechat receives the message normally, and the individual wechat cannot receive the message:
1. Enter “My Enterprise” → “wechat plug-in”, drag it to the bottom, check “Allow members to receive and reply to chat messages in wechat plug-in”
2. Close the restriction of “accept messages only in enterprise wechat” in “ME” → “Settings” → “New Message Notification” on the enterprise wechat client
5. Add environment variables
Add three variables to Github Secrets:
- The Name is
WX_APP_ID
Value is for step 2AgentId
. - The Name is
WX_APP_SECRET
Value is the second stepSecret
. - The Name is
WX_COMPANY_ID
Value is for step 3Enterprise ID
.
WX_COMPANY_ID= Enterprise ID WX_APP_ID= Application ID WX_APP_SECRET= Application Secret TIAN_API_KEY= Key of the day dataCopy the code
6.GitHub Action is automatically executed every day
The core code is as follows, and the detailed code is shown in the warehouse link below
schedule:
Beijing time = Standard time +8 18 indicates 2 am Beijing time
# at 7:30 in the morning
- cron: '30 * * *'
Copy the code
Data enablement API
Here we can choose third-party open apis to customize, or customize ourselves
Note: Free open source interface needs to consider service stability!
At present, the interface data capability is mainly provided by Tianxing data. You can register an account member without threshold
Day data: www.tianapi.com/
- Number of free interfaces for members: 15
- Number of gifts per day: 100
Note: If this interface is adopted, you need to add the variable of Key in step 5. Adding environment variables as a mandatory parameter when using the tianrow data interface
Features and Content
Here depends on personal ideas and ideas, the various free interface can provide a lot of various information, you can also write their own services and crawler scripts, the playability is really very high
The following features have been added:
- Personalize information
- The weather information
- A word a day
- The most beautiful song lyrics
- Shocking jokes
- Earthy…
- Daily English
- Bedtime story
The content is completely up to you, and then you can develop your own profile and news feed, which is great
Part of the code
Interface code
class API {
key: string
constructor(key? :string) {
this.key = key || ' ' // For convenience, add key in HTTP
}
// The most beautiful song poem
async getSongLyrics() {
const res = await getTian<IVerseProps[]>({ url: LoveMsgURL.songLyrics })
returnres? .0]}// A beautiful Sentence every day
async getDayEnglish() {
const res = await getTian<ResEnglishProps[]>({ url: LoveMsgURL.dayEnglish })
returnres? .0]}// Get lunar information
async getLunarDate(date: string) {
const res = await getTian<ResLunarDateProps[]>({ url: LoveMsgURL.lunarDate, params: { date } })
returnres? .0]}//
async getSaylove() {
const res = await getTian<SayloveProps[]>({ url: LoveMsgURL.saylove })
returnres? .0]}}export default new API()
Copy the code
Good morning, good afternoon, good night
const { MESSAGE_TYPE } = process.env
export default function main() {
if (MESSAGE_TYPE === 'goodAfternoon') {
/ / good afternoon
goodAfternoon()
} else if (MESSAGE_TYPE === 'goodEvening') {
/ / good night
goodEvening()
} else {
Good morning / /
goodMorning()
}
}
Copy the code
Request data -goodMorning
/ * * *@name goodMorning
* @description Say good morning * /
// Parallel request, optimal ring corresponding
const dataSource = await Promise.allSettled([
API.getSaylove(), //
API.getCaihongpi(), / / rainbow fart
API.getOneWord(), / / a word
API.getSongLyrics(), // The most beautiful song poem
API.getOneMagazines(), / / one magazine
API.getNetEaseCloud(), // NetEase Cloud reviews
API.getDayEnglish(), // Everyday English
])
// Filter out abnormal data
const [sayLove, caiHongpi, oneWord, songLyrics, oneMagazines, netEaseCloud, dayEnglish] =
dataSource.map((n) = > (n.status === 'fulfilled' ? n.value : null))
Copy the code
The effect
The weather information
Other information
Famous writers came to our city to sign autographs. Early in the morning, I brought my son to the bookstore to buy a book. When I asked the author to sign it, my son asked me in bewilderance, "How can we write his name on the book we buy?" A word: The reason why winter is so cold is to tell us how important the warmth of people around us is. While there is life, there is hope. Where there is life, there is hope.Copy the code
code
The project is developed using TypeScript and the package management tool is PNPM
The complete code can be seen in the warehouse, which has been open source github.com/JS-banana/n…
Welcome to communicate with us.
The development of
Copy the.env.example file and rename it to.env and fill in the corresponding values as required
If you want to use GitHub Action, you need to add a variable in Secrets
conclusion
How to say, you can find many interesting projects and gadgets on GitHub every day. If you spend some time on GitHub every day, you can not only learn about the technology, but also come into contact with many excellent content and projects for the first time.
The project was generally very simple, much simpler than writing a business, but it was a lot of fun, and it was a way to fall in love with coding. It’s easy to get bored and tired of boring business work, but technology itself is supposed to bring us fun and happiness, right
Today you are warm male 😉