Skip to content

引入

ts
import {
  fetchWeatherData,
  sendWeatherRobotMsg,
  getWeatherRobotContent
} from 't-comm';

// 不支持 tree-shaking 的项目
import {
  fetchWeatherData,
  sendWeatherRobotMsg,
  getWeatherRobotContent
} from 't-comm/lib/weather/index';

// 只支持 ESM 的项目
import {
  fetchWeatherData,
  sendWeatherRobotMsg,
  getWeatherRobotContent
} from 't-comm/es/weather/index';

fetchWeatherData()

描述:获取天气信息

参数

返回: Promise.<Array>

天气数据

示例

typescript
fetchWeatherData().then(content => {
  console.log(content)
})

sendWeatherRobotMsg(options)

描述:获取天气信息并发送

参数

参数名类型描述
optionsobject配置
options.webhookUrlstring机器人hook地址
[options.chatId]string会话Id
[options.force]string是否在和之前获取数据相同时,也发送

返回: Promise.<Object>

请求Promise

示例

ts
await sendWeatherRobotMsg({
  webhookUrl: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx',
  chatId: ['chat-id-1', 'chat-id-2'],
  force: false, // 默认 false:和上次数据一致时不发送
});

getWeatherRobotContent()

描述:获取深圳天气信息,可用于通过机器人发送到群聊

参数

返回: object

天气信息和是否有变化

示例

typescript
getWeatherRobotContent().then(resp => {
  const { content, isSame } = resp

  console.log(content)
  // ## 深圳当前正在生效的预警如下
  // ...

  console.log(isSame)
  // false
})