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

getWeatherRobotContent()

描述

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

参数

返回: object

天气信息和是否有变化

示例

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

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

  console.log(isSame)
  // false
})